What does the 'new' keyword before the parameter list mean in a typscript arrow function? [duplicate] What does the 'new' keyword before the parameter list mean in a typscript arrow function? [duplicate] typescript typescript

What does the 'new' keyword before the parameter list mean in a typscript arrow function? [duplicate]


It's a constructor type. It means that when you invoke it with new, you can give it a props argument and an optional context argument, and it'll construct an instance of type T.

Here's an example:

class Foo {    private value: number;    constructor(x: number, y: number = 1) {        this.value = x + y;    }}const foo: new (arg1: number, arg2?: number) => Foo = Foo;// can be invoked like this (with new)const x1: Foo = new foo(1);const x2: Foo = new foo(1, 2);// cannot be invoked without new// these lines will error at both compile- and run-timeconst y1: Foo = foo(1);const y2: Foo = foo(1, 2);