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

String templates doesn't work with nested generics and keyof #56582

Closed
f3oall opened this issue Nov 29, 2023 · 1 comment Β· Fixed by #56598
Closed

String templates doesn't work with nested generics and keyof #56582

f3oall opened this issue Nov 29, 2023 · 1 comment Β· Fixed by #56598
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@f3oall
Copy link

f3oall commented Nov 29, 2023

πŸ”Ž Search Terms

String templates doesn't work with nested generics and keyof

πŸ•— Version & Regression Information

5.2.2, 5.3

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.2#code/JYOwLgpgTgZghgYwgAgIIB4AqyIA9IgAmAzsgEoQID2Uh6xYUoA5gDTINMjMB8yA3gChkyEBAYRCALmSZBAX0FKYAVxAIwwKiGRwsOfBCKkM-YNI6MW8njwAUYGZgCUA4cgBGD9gHJzP1wB6QORmKipCdy8wXwBafyCQgCEVZgB+BUFVdU1tT308AhI0dDgQAE9bByd2YhpHZABrCHKqGFkAbR8xCUIfAF1kADJLLmZkAB9kAANYgBJ+Ztb2zC6eyD7Bkc5radchTKA

πŸ’» Code

interface A<T extends Record<string, string> {
  nested: T
}


function a<T extends A<{id: string}>>(t: T) {
  b(t, 'id') // good
  b(t, '-id') // Bug?
}
function b<T extends A<any>>(t: T, sort: keyof T['nested'] & string | `-${keyof T['nested'] & string}`) {

}

πŸ™ Actual behavior

Template string doesn't work as expected

πŸ™‚ Expected behavior

The example should compile without error

Additional information about the issue

No response

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Nov 29, 2023
@ahejlsberg ahejlsberg self-assigned this Nov 29, 2023
@ahejlsberg
Copy link
Member

Yeah, that ought to work. Here's a simpler repro:

function a<T extends {id: string}>() {
  let x: keyof T & string | `-${keyof T & string}`;
  x = "id";  // Ok
  x = "-id";  // Error, but should be ok
}

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants