-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed as not planned
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Hello,
I have the following piece of code that allows me to produce an invalid partial object:
type A = { a: number; b: string };
const buildPartial = (key: keyof A, val: A[keyof A]): Partial<A> => ({ [key]: val });
const test = buildPartial('a', 'hello'); // allows me to build an invalid object without compile error
Shouldn't I have a compile error? { [key]: val }
seems to of type { a: number | string } | { b: number | string }
which is not compatible with Partial
Thanks
ps: I understand I should have written const buildPartial = <K extends keyof A>(key: K, val: A[K]) => ...
My question is not on this, it is on why this was not caught by the compiler
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created