I would like to infer the types of a constructor of a class and map them to an Object. I can use ConstructorParameters, but this gives me a Tuple which I would need to transform to an Object. Here is what I'm trying to do:
type ToObject<T> = ???
export class ValueObject {
constructor(readonly username: string, readonly password: string) {}
static create(value: ToObject<ConstructorParameters<typeof ValueObject>>): ValueObject {
return new ValueObject(value.username, value.password)
}
}
ValueObject.create({ a: 'foo', b: 'bar' }) // KO
ValueObject.create(['foo', 'bar']) // KO
ValueObject.create({ username: 'foo', password: 1 }) // KO
ValueObject.create({ username: 'foo', password: 'bar' }) // OK
How could I achieve this?