Skip to content

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

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

Closed
ehmicky opened this issue Jan 15, 2024 · 4 comments
Closed

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

ehmicky opened this issue Jan 15, 2024 · 4 comments

Comments

@ehmicky
Copy link

ehmicky commented Jan 15, 2024

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

@ehmicky ehmicky 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 Jan 15, 2024
@fatcerberus
Copy link

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

@ehmicky
Copy link
Author

ehmicky commented Jan 15, 2024

Thanks @fatcerberus. I can confirm this,as the following code works:

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

@whzx5byb
Copy link

Duplicate of #48070

@ehmicky
Copy link
Author

ehmicky commented Jan 15, 2024

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

@ehmicky ehmicky closed this as completed Jan 15, 2024
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