In this paper, we introduce the topological state derivative for general topological dilatations and explore its relation to standard optimal control theory. We show that for a class of partial differential equations, the shape-dependent state variable can be differentiated with respect to the topology, thus leading to a linearised system resembling those occurring in standard optimal control problems. However, a lot of care has to be taken when handling the regularity of the solutions of this linearised system. In fact, we should expect different notions of (very) weak solutions, depending on whether the main part of the operator or its lower order terms are being perturbed. We also study the relationship with the topological state derivative, usually obtained through classical topological expansions involving boundary layer correctors. A feature of the topological state derivative is that it can either be derived via Stampacchia-type regularity estimates or alternately with classical asymptotic expansions. It should be noted that our approach is flexible enough to cover more than the usual case of point perturbations of the domain. In particular, and in the line of (Delfour in SIAM J Control Optim 60(1):22–47, 2022; J Convex Anal 25(3):957–982, 2018), we deal with more general dilatations of shapes, thereby yielding topological derivatives with respect to curves, surfaces or hypersurfaces. To draw the connection to usual topological derivatives, which are typically expressed with an adjoint equation, we show how usual first-order topological derivatives of shape functionals can be easily computed using the topological state derivative.