Skip to content

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

Closed

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.

Activity

  1. changed the title [-]Different behavior when using a type as is, or as a declared `type`[/-] [+]Different behavior when using a type as is, or as a type alias[/+] on Jan 15, 2024
  2. fatcerberus commented on Jan 15, 2024

    @fatcerberus

    Looks like a variance measurement issue (A is erroneously measured as covariant)

  3. ehmicky commented on Jan 15, 2024

    @ehmicky
    Author

    Thanks Bruce Pascoe (@fatcerberus). I can confirm this,as the following code works:

    type A<in T> = {a: T extends true[] ? true : false};
  4. whzx5byb commented on Jan 15, 2024

    @whzx5byb

    Duplicate of #48070

  5. ehmicky commented on Jan 15, 2024

    @ehmicky
    Author

    Thanks whzx5byb and sorry for the duplicate. Closing in favor of #48070.

  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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