镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Closed

Description

🔎 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

Activity

  1. ahejlsberg commented on Nov 29, 2023

    @ahejlsberg
    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
    }
    
  2. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions