#Is it possible to access constructor with indexed access types?

1 messages · Page 1 of 1 (latest)

true linden
#

I would like create a wrapper function that declares sane defaults for initializing an object. Hence, I would like to declare my wrapper function's parameter as Partial<ObjectThatIWantToInitialize['constructor']> but this is not working. Do I have any options other than manually declaring the constructor's parameter types?

echo void
#

can you show an example of how you want to use this wrapper function with a real constructor?

patent aurora
#

I don't understand exactly what you are asking, but if you want to extract the parameter list of the constructor, there is ConstructorParameters

class Thing {
    constructor(a: number, b: string) {}
}

type A = ConstructorParameters<typeof Thing>; // [a: number, b: string]```