I have learned about such feature in TypeScript as "Construct Signatures"
It allows to declare types such as:
type PointCreator = {
new (x: number, y: number): {x: number, y: number},
test(test:number): number,
(foo:number): number,
}
How would I go about creating an object of this type?
When I am trying to declare an object of this type: I am getting an error "Type 'typeof PointCreation' is not assignable to type 'PointCreator'. Type 'typeof PointCreation' provides no match for the signature '(foo: number): number'.
const PointCreation: PointCreator = class {
constructor(public x: number, public y: number) {}
static test = (test:number) => {return test;};
bloo = (foo:number) => {return foo;};
}
Also, I do not understand why function test()
is required to be static
.
If I to remove static
keyword another compiler error appears:
Property 'test' is missing in type 'typeof PointCreation' but required in type 'PointCreator'.
When trying to declare a type with either a constructor, or a bunch of functions, it is very easy to write a corresponding object.