π 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 |
 |
 |
β― 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