Issue
Does anyone know why partialType does not make properties nullable? It adds @IsOptional to properties which also allow null as a valid value, however the type returned from partialType only returns T | undefined instead of T | undefined | null, which causes a problem in TypeScript's strict null check mode. I opened an issue about it; the contributor said it's an expected behavior, but I don't see how.
Solution
Can be fixed by wrapping partialType with NullableType
type Nullable<T> = {
[P in keyof T]: T[P] | null;
};
export function NullableType<T>(classRef: Type<T>): Type<Nullable<T>> {
return classRef as Type<Nullable<T>>;
}
Answered By - omidh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.