new () => T Construct Signatures
Last updated: 2026-10-22
new () => T Construct Signatures
A construct signature new (name: string) => T describes "this value can be new-ed into a T". You need it when passing classes (not instances) around — factories, dependency injection and plugin systems all rely on it to abstract "the ability to build".
| Group | Functions & Classes |
|---|---|
| Kind | Syntax |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
class Player {
constructor(public name: string, public hp = 100) {}
}
type PlayerCtor = new (name: string, hp?: number) => Player;
function spawn(Ctor: PlayerCtor, name: string, hp?: number): Player {
return new Ctor(name, hp);
}
⚙️ Parameters
| new | The construct-signature prefix: this signature is invoked with new, not called directly |
|---|---|
| (name: string, hp?: number) | Constructor parameters: positionally matching the class constructor |
| => Player | The produced type: the result of the new expression |
Returns:The type on the right of =>, which is the result of the new expression; factories typically pass it through as their own return type.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
Ada hp=100, Ben hp=80
(Runtime output after transpilation; passing a class whose constructor does not match is a compile error)
💡 Notes
ℹ️ Info A class itself is the value of its construct signature: you pass the Player reference and the factory does the new-ing — the type-level form of "classes are first-class".
💡 Tip The generic factory new (...args: any[]) => T is minimal DI: pass any class, get a T. Use InstanceType<typeof C> when exact constructor parameters matter.
⚠️ Note Abstract classes do not satisfy concrete construct signatures (they cannot be new-ed directly); use an abstract construct signature abstract new (...) => T for "class or subclass".
🏷️ Related Functions & Classes
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q Construct signature vs InstanceType<typeof Player>?
A typeof Player is the class itself with statics and exact constructor parameters; new (...) => T only promises "new-able into T". Exact: former. Generic factories: latter.
Q When is a construct signature required?
A Whenever a class is passed as a value: spawn(PlayerCtor, name), container registration, plugin loading. Interfaces describe instances, not classes.
Q How to write a generic factory that is both generic and type-safe?
A function create<T>(Ctor: new (...args: any[]) => T, ...args: any[]): T { return new Ctor(...args); } — loose inputs buy genericity, the return stays a precise T.