-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
🔎 Search Terms
is:issue is:open incompatible types comparison
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about common bugs, tried searching for equality and comparisons.
⏯ Playground Link
Playground link with relevant code
💻 Code
type Opaque<Type, Token = unknown> = Type & {
readonly __opaque__: Token
}
type One = Opaque<number, 'One'>
type Two = Opaque<number, 'Two'>
const one: One = 1 as One
const two: Two = 2 as Two
console.log(one === two) // error - incompatible types
console.log(one == two) // error - incompatible types
console.log(one < two) // works? why?🙁 Actual behavior
The current behavior feels unexpected to me. I would understand that this is due to JavaScript compatibility if equality checks would succeed.
Also in other programming languages that I know it's usually so that greater/less comparisons can be applied only to subset of types where equality can be applied. So if the errors would be other way around it would make sense for me.
So in my opinion currently the way TypeScript compiler works is confusing.
🙂 Expected behavior
I would expect to either:
- See errors everywhere - this is preferred behavior for me
- See errors nowhere
<comparison to error, while==and===to compile
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug