Syntax
type Args = ConstructorParameters<typeof Person>;
type PersonObject = InstanceType<typeof Person>;Examples
ConstructorParameters and InstanceType: working example
Run this standalone example after compiling with TypeScript 5.4+ in strict mode, targeting ES2022. Expected result: The program prints Ada: 3; changing the constructor’s parameter types updates the factory’s checked arguments.
class Person {
constructor(public name: string, public visits: number) {}
describe() { return `${this.name}: ${this.visits}`; }
}
type Args = ConstructorParameters<typeof Person>;
type PersonObject = InstanceType<typeof Person>;
function createPerson(...args: Args): PersonObject {
return new Person(...args);
}
console.log(createPerson("Ada", 3).describe());- Expected result: The program prints Ada: 3; changing the constructor’s parameter types updates the factory’s checked arguments.
- typeof Person refers to the constructor value’s type.
- The rest parameter receives the extracted tuple, preserving order and parameter types.
Best practices
- Prefer deriving factory signatures over duplicating argument lists.
- Be aware that overload-based extraction follows the final applicable signature rules.
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook