GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Normalize union/intersection type combinations by ahejlsberg · Pull Request #11717 · microsoft/TypeScript Conversation
|
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(18,5): error TS2322: Type 'A & B' is not assignable to type 'boolean'. | ||
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(19,5): error TS2322: Type 'A & B' is not assignable to type 'string'. | ||
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(21,5): error TS2322: Type 'number & boolean' is not assignable to type 'string'. | ||
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(21,5): error TS2322: Type '(number & true) | (number & false)' is not assignable to type 'string'. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is there some way to present this error as number & boolean still? I feel like the distributed form is unexpected here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The actual representation needs to be (number & true) | (number & false), but we could play tricks in the type-to-string logic to turn it into number & boolean. Not sure it's worth it though as those types are all rather meaningless anyway.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, type-to-string is what I was thinking of. But you're right, & boolean probably only shows up in our tests.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return result; | ||
| } | ||
| } | ||
| else if (source.flags & TypeFlags.Intersection) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
why not check the source first here too? I think that's the normal pattern for isRelatedTo
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The comment above the initial if statement explains why. For intersection types, the target side is an "each" relationship and the source side is a "some" relationship. We need to deconstruct "each" relationships first to get the correct results.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
OK, so I think I misunderstood the parts of the code that are independent post-distribution. It would work to put intersections before unions now, where it wouldn't before, right?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return result; | ||
| } | ||
| } | ||
| else if (source.flags & TypeFlags.Intersection) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
OK, so I think I misunderstood the parts of the code that are independent post-distribution. It would work to put intersections before unions now, where it wouldn't before, right?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(18,5): error TS2322: Type 'A & B' is not assignable to type 'boolean'. | ||
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(19,5): error TS2322: Type 'A & B' is not assignable to type 'string'. | ||
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(21,5): error TS2322: Type 'number & boolean' is not assignable to type 'string'. | ||
| tests/cases/compiler/errorMessagesIntersectionTypes04.ts(21,5): error TS2322: Type '(number & true) | (number & false)' is not assignable to type 'string'. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, type-to-string is what I was thinking of. But you're right, & boolean probably only shows up in our tests.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.