Introduce the "comparable" relation#5517
Conversation
src/compiler/diagnosticMessages.json
Outdated
There was a problem hiding this comment.
I prefer 'comparable to' here. A little research shows that grammarians think they're about equally common, while Google's hideously unreliable hit count shows 4 times more hits for 'comparable to'*.
But the function is also named isTypeComparableTo, so I think there's precedent. :)
*Google hit counts are the laziest way to do quantitative linguistics.
There was a problem hiding this comment.
Yeah, I couldn't decide, but I'm okay with either.
There was a problem hiding this comment.
"comparable" is an odd error to issue when complaining about a type assertion. Can we say "x cannot be converted to y" with the "comparable to" error as the next diagnostic chain?
Conflicts: src/compiler/checker.ts
|
@DanielRosenwasser can we close this. |
|
I'm planning to merge this in for the tests as a heads up. |
This pull request introduces a new relationship to check whether or not two types are "comparable to" one another. Specifically, it addresses the issues found in #5300 with union types and certain operations.
The new relationship generally subsumes the uses for assignability where we would check whether or not two types were assignable to or assignable from one another. These uses were in checking for compatibility between
===,!==,==,!=).caseclause expressions and their respectiveswitchexpressions.Like with other type relations, the comparable relation takes a source and a target. It is the most lenient relation, so types that are assignable are always comparable, but the reverse is not necessarily true. The comparable relation differs from the assignability relation in that if the source is a union type, the relation succeeds provided that any of its constituents are comparable to the target.
Keywords: comparability