ARTICLE AD BOX
I have a TypeScript class hierarchy where I want to infer types correctly for subclasses based on static methods. In the following code, I have a base class Z with a static method x, and a subclass Y that overrides this method. However, I'm unsure how to set up the constructor in Y so that it correctly infers the type based on the overridden static method. Here is the relevant code:
class Z { static x = (p: any) => ` ${typeof p.teste} ` constructor(...args: Parameters<typeof this.constructor['x']>) { } // ^^^^^^^^^^^^^^^^^^^^^^ I don't know what to put here to infer the correct type even for subclasses } class Y extends Z { static override x = (p: { teste: Date }) => `${typeof p.teste}` // here the constructor should not be declared, as it will be inherited from Z and should infer the correct type based on the override of the static method 'x' } new Y({ teste: "100" }) new Y({ teste: 100 }) new Y({ teste: new Date() }) // <-- only this one should be validHow can I modify the constructor in Y to ensure it infers the correct type based on the static method x? Any guidance or examples would be greatly appreciated!
Feel free to post this question on Stack Overflow for assistance!
