Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function allows me to build invalid partial #55672

Closed
f-g-p opened this issue Sep 7, 2023 · 2 comments
Closed

Function allows me to build invalid partial #55672

f-g-p opened this issue Sep 7, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@f-g-p
Copy link

f-g-p commented Sep 7, 2023

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

@f-g-p f-g-p added the Duplicate An existing issue was already created label Sep 7, 2023
@jcalz
Copy link
Contributor

jcalz commented Sep 8, 2023

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.

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants