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

Broken inference between type placeholders with non-string constraints in template literal types #57807

Closed
Andarist opened this issue Mar 16, 2024 · 0 comments Β· Fixed by #57808
Closed

Comments

@Andarist
Copy link
Contributor

πŸ”Ž Search Terms

inference types texts template literal types generic constraint string

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240316&ssl=17&ssc=24&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgHIFk4AdkG8BQyyAjAFzIBEAghQNyHIBM5FAQnQwMwsDCHRAFhYARDgF98+ACYQEAGzhQUCAPYgAzmGQBzcgB4AKsggAPSCCnqSyAD5NbyTgD4AFCfIADACS4DYjwCUyAC8TmiYWADaBgC69PhgAJ5YKADixCHIhsZmEBZWGXaMDs5unj5+gSFhGNjRcfiqGlraZMjpmdq0yAD0PcgqANaSSSntxcFZRqbmltZFJQ4Cru7I3r7+QaHhdbH0TZo6zOOd3X3GUFAqUCPJaZyZ2TN5c4VMK+UbVdu1UXuNakO2m47Qeky6vX6Q3wQA

πŸ’» Code

interface NMap {
  1: "A";
  2: "B";
  3: "C";
  4: "D";
}

declare const g: <T extends 1 | 2 | 3>(x: `${T}`) => NMap[T];

type G1 = <T extends 1 | 2 | 3>(x: `${T}`) => NMap[T];
const g1: G1 = g; // should be ok

type G2 = <T extends 1 | 2 | 3 | 4>(x: `${T}`) => NMap[T];
const g2: G2 = g; // should error

type G3 = <T extends 1 | 2>(x: `${T}`) => NMap[T];
const g3: G3 = g; // should be ok

πŸ™ Actual behavior

All of those assignments fail

πŸ™‚ Expected behavior

Only the second assignment should fail

Additional information about the issue

Originally reported by @gabritto here: #56659 (comment)

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