Template literal type reduction is inconsistent (regression in 5.5-beta) #58687
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.This is a new regression just found in the last major/minor version of TypeScript.
Milestone
Description
🔎 Search Terms
Template literal type reduction
🕗 Version & Regression Information
This changed in 5.5-beta (as reported in #58685).
⏯ Playground Link
💻 Code
const enum E { a = "a", b = "b" };
type Stringify<T extends string> = `${T}`;
let z1: `${E}` = "a"; // Ok
let z2: Stringify<E> = "a"; // Error!🙁 Actual behavior
Error as indicated.
🙂 Expected behavior
No error.
Additional information about the issue
This is a regression from 5.4.5. Error is caused by reduction introduced in #55371.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.This is a new regression just found in the last major/minor version of TypeScript.
Activity
ahejlsberg commentedon May 29, 2024
Previously,
`${T}`would always strip enum-ness. Following #55371, whenT extends string,`${T}`is simplified to justT, and enum-ness is no longer stripped. That's technically a breaking change. Furthermore, #55371 is inconsistent in that it doesn't simplify`${E}`to justEwhenEis an enum type. One way or the other, we should be consistent here. But I'm not really a fan of the change in #55371.ahejlsberg commentedon May 29, 2024
See my comment here. My recommendation is that we revert #55371.