How do you get a union of constructor args in a class?
Assume we have
class Person {
constructor(name: string, age: number){}
}
How would you get the type 'name' | 'age'
?
I have tried using
type ConstructorParametersOfPerson = ConstructorParameters<typeof Person>;
but this returns a tuple of the object [name: string, age: number]
and e.g, using ConstructorParametersOfPerson[0]
returns string
and somehow throws the parameter key away.