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".

GroupFunctions & Classes
KindSyntax
Strict modeNot 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

newThe construct-signature prefix: this signature is invoked with new, not called directly
(name: string, hp?: number)Constructor parameters: positionally matching the class constructor
=> PlayerThe 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".
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏