Skip to content

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

@Gguigre

Description

@Gguigre

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions