TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
new operator allocates memory and initializes a new instance of a class or constructor function. In TypeScript, it acts as a compile-time boundary that enforces strict type-checking against a target’s construct signature, validating both the provided arguments and the resulting instance type.
Syntax
Construct Signatures
TypeScript represents the type of a function that can be invoked withnew using a construct signature. This is defined using the new keyword preceding a function signature.
new operator, it looks up the construct signature of the operand. If the operand lacks a construct signature, the compiler throws a TS2351 error (“This expression is not constructable”).
Type Space vs. Value Space
A critical mechanic of thenew operator in TypeScript is how it interacts with class declarations. A class declaration creates exactly one type in the type space (representing the shape of the instantiated object) and one value in the value space (the constructor function itself, which contains the construct signature and static members).
To type a variable that holds the constructor itself (the target of the new operator), you must use the typeof operator on the class value to extract its type, or define a construct signature. The constructor’s type is not created as a distinct named type in the scope.
Generic Instantiation
When thenew operator is applied to a generic class or constructor, TypeScript performs type inference on the constructor arguments to determine the type parameters. Alternatively, type parameters can be explicitly provided via angle brackets < > immediately following the constructor name.
Abstract Classes
TypeScript prohibits thenew operator from directly instantiating abstract classes. Abstract classes possess an abstract new construct signature in their type representation. The compiler prevents instantiation by explicitly checking for the abstract modifier on the constructor type. When the new operator is applied to an abstract constructor, the compiler throws a TS2511 error (“Cannot create an instance of an abstract class”), ensuring the class can only be instantiated via a derived concrete class.
Master TypeScript with Deep Grasping Methodology!Learn More





