Closed
Description
🔎 Search Terms
type broadening, type narrowing, generics, generic type parameter, index type, template literal, typescript, unexpected, why doesn't typescript know that these are the same, same generic instance not enforced between function params
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about the same generic instance type being used in different function parameters
⏯ Playground Link
💻 Code
type Something = 'Something';
type SomethingElse = 'SomethingElse';
type TemplateType = `Something.${Something}` | `SomethingElse.${SomethingElse}`
function doSomethingWithMyThing<T extends Something | SomethingElse>(field: T, option: T) {
const myTemplate: TemplateType = `${field}.${option}`;
}
🙁 Actual behavior
The actual type of ${field}.${option}
is some sort of cartesian product of the types of field and option, causing the TemplateType
type of myTemplate
to be incorrect.
🙂 Expected behavior
The type of ${field}.${option}
should be either "Something.Something" or "SomethingElse.SomethingElse" based on the same T
being enforced between the two params.
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
No labels