You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Looks like you used the wrong template to file a bug report.
Caused by #13948 making an index signature and maybe #27144 not checking against the weak type... so this probably is indeed a duplicate, not that you intended to file it as one.
Hello,
I have the following piece of code that allows me to produce an invalid partial object:
Shouldn't I have a compile error?
{ [key]: val }
seems to of type{ a: number | string } | { b: number | string }
which is not compatible with PartialThanks
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 compilerThe text was updated successfully, but these errors were encountered: