-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Don't use a cached union/intersection type if there is an aliasSymbol #17349
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
Conversation
86ea47f
to
af108c0
Compare
af108c0
to
82d68fc
Compare
@@ -1,32 +1,32 @@ | |||
=== tests/cases/conformance/types/literal/booleanLiteralTypes1.ts === | |||
type A1 = true | false; | |||
>A1 : boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behaviour is intended. I don't know that it's super important. It's probably even less important that
type A = { a }
type B = { b }
type T = A | B
type U = A | B
declare var t: T
declare var u: U
should also print either T
or U
(or A | B
) for both t
and u
.
It's more important that:
declare var x: true | false
prints 'boolean' for the type of x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahejlsberg can you weigh in on true | false
and boolean
being equivalent to type B = true | false
?
>true : true | ||
>false : false | ||
|
||
var a: false | true; | ||
>a : boolean | ||
>a : A1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looked wrong until I realized that this is the fourth declaration of a
, and the first declaration has type A1
, which is the type shown here.
There is a test below showing that a variable whose only declaration is of type true | false
will still print as boolean
.
Closing in favor of #17434. |
It's not safe to cache the creation of a value based on only some of the inputs to that creation. This updates the code to not cache the creation of a type alias with
aliasSymbol
defined. (Presumably we will never create a type for the same symbol twice?)