Closed stevehanson closed 3 years ago
The DeepPartial type, which is used to define what can be passed as params to a factory, was not working properly with some types, notably indexed types and arrays that could be null or undefined.
DeepPartial
params
Previously:
DeepPartial<{ objectArray: { x: number }[]; objectArrayNull: { x: number, y: number }[] | undefined | null; stringArrayNull: string[] | undefined | null; params: { [name: string]: string[] | undefined | null; }; }>
generated this type:
{ objectArray?: { x: number; }[] | undefined; objectArrayNull?: (DeepPartial<{ x: number; y: number }> | undefined)[] | null | undefined; stringArrayNull?: (string | undefined)[] | null | undefined; params?: DeepPartial<{ [name: string]: string[] | null | undefined; }> | undefined; }
The most notable issues were:
objectArrayNull
[undefined]
[{ x: 1 }]
merge
The new DeepPartial generates:
{ objectArray?: { x: number; }[] | undefined; objectArrayNull?: { x: number; }[] | undefined | null; stringArrayNull?: string[] | undefined | null; params?: DeepPartialObject<{ [name: string]: string[] | null | undefined; }> | undefined; }
This PR also adds tests that document and verify the new type.
Closes #67
The
DeepPartial
type, which is used to define what can be passed asparams
to a factory, was not working properly with some types, notably indexed types and arrays that could be null or undefined.Previously:
generated this type:
The most notable issues were:
objectArrayNull
would accept[undefined]
(shouldn't allow undefined entries)objectArrayNull
would accept[{ x: 1 }]
(partial object inside of an array -- ourmerge
implementation does not partial merge arrays)params
was resulting in the factory itself not compiling as described in #67The new
DeepPartial
generates:This PR also adds tests that document and verify the new type.
Closes #67