Skip to content

Regression with template literal generics (4.3.0-beta) #43620

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
zkrising opened this issue Apr 9, 2021 · 1 comment Β· Fixed by #43661
Closed

Regression with template literal generics (4.3.0-beta) #43620

zkrising opened this issue Apr 9, 2021 · 1 comment Β· Fixed by #43661
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@zkrising
Copy link

zkrising commented Apr 9, 2021

Bug Report

πŸ”Ž Search Terms

Template Literal Generic
Template Literal Discrimination
Template Literal Resolution

πŸ•— Version & Regression Information

  • This changed between versions 4.2.3 and 4.3.0-dev20210408

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Prefixes = "foo" | "bar";

// Create a type which is an set of strings
type AllPrefixData = "foo:baz" | "bar:baz";

// Then create a generic type that generates a compliant member of that set
type PrefixData<P extends Prefixes> = `${P}:baz`;

// Create an interface with a generic that expects E to extend AllPrefixData.
// However, even though PrefixData<P> is a valid member of AllPrefixData,
// it will be rejected in 4.3.0.
interface ITest<P extends Prefixes, E extends AllPrefixData = PrefixData<P>> {
    blah: string
}

πŸ™ Actual behavior

TypeScript 4.3.0-dev rejects the assignment with the following nonsense error:

    Type '`${P}:baz`' does not satisfy the constraint 'AllPrefixData'.
      Type '`${P}:baz`' is not assignable to type '"bar:baz"'.
    'E' is declared but its value is never read.

πŸ™‚ Expected behavior

This should be a legal assignment, and was until 4.3.0-dev.

@andrewbranch andrewbranch added the Bug A bug in TypeScript label Apr 9, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.3.1 milestone Apr 9, 2021
@andrewbranch
Copy link
Member

I think this looks like a 4.3 regressionβ€”@ahejlsberg, would you be able to take a look?

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.

4 participants