Produce a more complete union of string literal template interpolations when the same const appears multiple times #49132
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Bug Report
When using a constant union of two types, using the value below will always infer it to still be either or both types although as a const it can only be one.
🔎 Search Terms
duplicate key union
🕗 Version & Regression Information
Seen in most recent version of TS (4.6.2) and every version available on the playground.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Typescript throws error
Element implicitly has an 'any' type because expression of type '"guestguest" | "guestservice" | "serviceguest" | "serviceservice"' can't be used to index type '{ guestguest: string; serviceservice: string; }'. Property 'guestservice' does not exist on type '{ guestguest: string; serviceservice: string; }'.(7053)
as this is a const, it is impossible for it to still be an either/or, so multiple instances of the variable should all be equal.
In this case, only guestguest or serviceservice should be possible
🙂 Expected behavior
Typescript should correctly infer the key options to be only a combination of one of the options, and not any possible combination.
The text was updated successfully, but these errors were encountered: