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

Template literal type reduction is inconsistent (regression in 5.5-beta) #58687

Closed
ahejlsberg opened this issue May 29, 2024 · 2 comments Β· Fixed by #58702
Closed

Template literal type reduction is inconsistent (regression in 5.5-beta) #58687

ahejlsberg opened this issue May 29, 2024 · 2 comments Β· Fixed by #58702
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.

Comments

@ahejlsberg
Copy link
Member

ahejlsberg commented May 29, 2024

πŸ”Ž Search Terms

Template literal type reduction

πŸ•— Version & Regression Information

This changed in 5.5-beta (as reported in #58685).

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-beta&ssl=7&ssc=1&pln=1&pc=1#code/MYewdgzgLgBApmArgWxgURgbxgQxgXhgCIciAaGAIwOMqJgF8BuAKBagE8AHOGAZSgAnAJZgA5sIBmHADwAVeAA8oCACYQY0EeIB8NAAYASTHIb7WLADZxYALwCMALhhHMaMzRJEmMX398A9AEwAPIA1lY2MLYATM4C2hLSMmh6hF4+MEHogoIgggCELEA

πŸ’» 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.

@ahejlsberg ahejlsberg added Bug A bug in TypeScript Recent Regression This is a new regression just found in the last major/minor version of TypeScript. labels May 29, 2024
@ahejlsberg ahejlsberg added this to the TypeScript 5.5.1 milestone May 29, 2024
@ahejlsberg
Copy link
Member Author

ahejlsberg commented May 29, 2024

Previously, `${T}` would always strip enum-ness. Following #55371, when T extends string, `${T}` is simplified to just T, 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 just E when E is 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
Copy link
Member Author

See my comment here. My recommendation is that we revert #55371.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.
Projects
None yet
2 participants