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

Inconsistent extends check when comparing a directly written generic (Template<'a'>) to a type-aliased version of the same generic (TA = Template<'a'>) #61548

Open
Gguigre opened this issue Apr 7, 2025 · 3 comments

Comments

@Gguigre
Copy link

Gguigre commented Apr 7, 2025

πŸ”Ž Search Terms

"Alias equality", "extends broken by alias template", "generic type extension", "extends transitivity typescript"

πŸ•— Version & Regression Information

  • This changed between versions 4.1.5 and 4.2.3
4.1.5 4.2.3
Image Image

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAgg8gJwEJQLxQOQEMNQD6YBGGAUCaJLIkgAoID2YAzmlAN4lRQUQBcmOTlCaQAxvwwiIoqIIC++dkJ78ARIVVCp4zNqjEScsjygAVCAFswAGyzAIAHlNQIAD3sA7ACYt4yVti4BBjEAHys7FAA9FHcABYAliyiWACuTBAswHHQhKkA5srgfGZaYvwAou4IWKLADn60DMwANOwqZnKhANqq2qoAuobGxWYwrOZWtvYOgaEjlABKmQCME5Y2do5zLu4Q3iyTm-ZQAPzcCKnQ-ABmWNYZ0bFMcfSp1l760HcP0FjeUCSUB+j34gFByEgxLhQAB6pwW0GWTAATBNxm5PD4zBtptBzsBLtdgfdHlCXm8Pl9ib9ZACgQSrlB+IAZckhsVh8LIZKwFlyBUBNygAEkoOloDx6IKALQy2Vy+VykiiegeJjAKBgVgcLgdQItMrSCR6eSyZIqtUIqBIgDMrAlgs1GP2WKOuLOF0ZtxJ0DJr3en0I329tM+9MJTKgrKhXDhQA

πŸ’» Code

type AOrB = 'a' | 'b'

type AOrBProps = {
  type: 'a'
  spec: 'spec a'
} | {
  type: "b"
  spec: 'spec b'
}

type Template<T extends AOrB = 'a' | 'b'> =  { // this causes the bug
  type: T
  spec: Extract<AOrBProps, {type: T}>["spec"]
}

type TA = Template<'a'>

type Res1 = Template<'a'> extends Template ? true : false // should be false and is false : βœ…
//   ^?

type Res2 = TA extends Template ? true : false // should be false and is true : ❌
//  ^?


// same bug if I use typeof -------------------
const p = {
  type: 'a',
  spec: 'spec a'
} as const

type Res3 = typeof p extends Template ? true : false // should be false and is true : ❌
//   ^?

πŸ™ Actual behavior

Types declared as equals (TA and Template<'a'>) does not behave the same when compared to a third type (Template)

πŸ™‚ Expected behavior

As TA = Template<'a'> I would expect Res1 and Res2 to be the same (false)

Additional information about the issue

Working on this issue with @GuillaumeEgret

@MartinJohns
Copy link
Contributor

Sounds like a duplicate of #60503.

@GuillaumeEgret
Copy link

Yes, seems likea duplicate but the other issue was automatically closed because there was no update. Should we investigate what broke the type aliasing ?

@MartinJohns
Copy link
Contributor

the other issue was automatically closed because there was no update

It was closed because it was marked as a "Design Limitation", which means there's nothing they can do about it in the foreseeable future.

Should we investigate what broke the type aliasing ?

πŸ€·β€β™‚ I'm not a team member. But if you have a fix that doesn't have horrendous performance costs and doesn't break anything else I'm sure the team would be happy to accept it.

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

3 participants