Is there a way to reuse the argument type definition of a class constructor without refactoring or extracting it from the class itself? I have tried using GetProps<TBase>
, but it doesn't work as expected. In the example below, the const bp
definition should throw an error because it is missing the derp
field which is defined in the constructor.
type GetProps<TBase> = TBase extends new (props: infer P) => any ? P : never
class Bro {
bro: string = 'cool'
cool: string = 'lol'
constructor(props: {bro: string, cool: string, derp: string}){
this.bro = props.bro;
this.cool = props.cool;
}
}
const bp : GetProps<Bro> = {
bro: 'lol',
cool: 'wut'
};