Skip to content

Different behavior when using a type as is, or as a type aliasΒ #57062

Closed
@ehmicky

Description

@ehmicky

πŸ”Ž Search Terms

type alias
extends array
different behavior

πŸ•— Version & Regression Information

This was introduced by version 4.2, and continues as of today (version 5.3).

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.3#code/C4TwDgpgBAggPAFQHxQLxQN4EMBcUFQQAewEAdgCYDOUwATgK4QDaAulAPy2PR4BmWADZUIAXwDcAWABQM0JCgAhNLDj0mbJOKgB6HZlzcmoueGgBhFfABGAe1uCIWMpu16D-ISJPT50ACJWajyahCTk1FCWXOq8UALCEG76AAYJIikANFAA7gAWAJYAxnlQBTRFtnR0EEXApgoAokGxocSklDQ29o7OoTE8UJ6JyVApsVm5hSVlNAVkldW1wEA

πŸ’» Code

type A<T> = {a: T extends true[] ? true : false};

type B = A<true[]>; // {a: true}
type C = A<boolean[]>; // {a: false}
type D = A<true[]> extends C ? true : false; // `false`, which is correct
type E = A<true[]> extends A<boolean[]> ? true : false; // `true`, which is incorrect

πŸ™ Actual behavior

The types D and E have different values.

πŸ™‚ Expected behavior

The types D and E should have the same value since they are identical, except for one using a type alias.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions