Skip to content

Unwanted Template string product when same union is used multiple times. #61160

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

Closed
nicu-chiciuc opened this issue Feb 10, 2025 · 1 comment
Closed

Comments

@nicu-chiciuc
Copy link

🔎 Search Terms

"template cartesian product", "cross-product of same union", "template string multiple"

🕗 Version & Regression Information

behaves exactly the same

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABFApgZygCgG4EMA2AXIgEQCCFJiAPqQEIMkCUiA3gLABQiiECGiAE4ooiALyIABgBJWefAF8AtLPkLJiXGl78oAbi48A9EcQAVAJ4AHFIhhhgKQcIAmm7eQpKKZKrU9kSgx0fvQM3pQ0YXRBjIaIJnZgGCi4bnDApD4RvlEkwbEhXApAA

💻 Code

function test(val: "AAA" | "BBB") {
  const ret = `${val}-${val}` as const;
  // Type inferred as "AAA-AAA" | "AAA-BBB" | "BBB-AAA" | "BBB-BBB"
  // instead of "AAA-AAA" | "BBB-BBB"
}

🙁 Actual behavior

Type inferred as "AAA-AAA" | "AAA-BBB" | "BBB-AAA" | "BBB-BBB" when a union is used twice in same template string.

🙂 Expected behavior

It should be possible to infer that ret can only be "AAA-AAA" | "BBB-BBB"

Additional information about the issue

This issue seems similar: #57427

@jcalz
Copy link
Contributor

jcalz commented Feb 10, 2025

search in:title template literal union

Duplicate of #49132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants