Skip to main content
An abstract method in TypeScript is a method signature declared within an abstract class that lacks an implementation body. It serves as a strict compile-time structural contract, mandating that any concrete (non-abstract) subclass inheriting from the base class must provide the explicit implementation for that method. Because they are a TypeScript-only type-checking construct, abstract methods are entirely erased during compilation and emit no JavaScript code.

Technical Characteristics

  • Enclosure Requirement: Abstract methods can only exist inside classes that are explicitly prefixed with the abstract keyword. Attempting to declare an abstract method in a standard class will result in a compiler error.
  • Declaration Structure: The declaration must include the abstract keyword, optional access modifiers, the method name, and parameters. While the return type is syntactically optional in loose configurations, modern TypeScript environments with strict (or noImplicitAny) enabled require an explicit return type to prevent compiler error TS7010. The declaration must end with a semicolon rather than an implementation block.
  • Modifier Restrictions: The abstract modifier cannot be combined with the static modifier. Attempting to do so produces compiler error TS1243 ('abstract' modifier cannot be used with 'static' modifier). Additionally, abstract methods cannot be combined with the async modifier, as async dictates implementation behavior rather than signature structure (to enforce asynchronous behavior, specify a Promise return type instead).
  • Access Modifiers: Abstract methods can be declared as public or protected. They cannot be declared as private, as the derived class must be able to access and implement the method.
  • Signature Compatibility and Variance: The TypeScript compiler enforces structural compatibility for the overriding method.
    • Return Types: The concrete method can be covariant in its return type (returning a narrower, more specific type than the abstract signature).
    • Parameters: Using standard method syntax, TypeScript parameters are bivariant. This means a derived class is permitted by the compiler to narrow or widen the parameter types. To enforce strict contravariance (requiring the derived class to accept identical or wider types, preventing unsafe narrowing), the abstract member must be defined using function property syntax combined with the strictFunctionTypes compiler option. Parameters can also be safely omitted in the implementation.
  • The override Keyword: When implementing an abstract method, it is standard practice to use the override keyword. This instructs the compiler to verify that the method actually overrides a base class member. It is strictly required if the noImplicitOverride compiler option is enabled in tsconfig.json.
  • Implementation Deferral: If a derived class is also declared as abstract, it is not required to implement the inherited abstract methods. The compile-time obligation to implement them propagates down the class inheritance hierarchy until a concrete class is defined.
  • Runtime Erasure: Abstract methods do not exist at runtime. They leave no trace on the JavaScript prototype chain, functioning purely as a design-time enforcement mechanism.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More