🔎 Search Terms
generics templates comparison compare less-than more-than unknown unsound function inline
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about relational operators and comparisons
⏯ Playground Link
https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true&noUnusedLocals=true&noUnusedParameters=true&target=10&jsx=0&useUnknownInCatchVariables=true&exactOptionalPropertyTypes=true&noFallthroughCasesInSwitch=true&noImplicitOverride=true&noPropertyAccessFromIndexSignature=true&suppressImplicitAnyIndexErrors=true&ts=5.6.0-dev.20240619&noStrictGenericChecks=true#code/MYewdgzgLgBMC2AHGBeGAeAKgGgHwAoAPALhhxgE9TMBKVXGQjSgWACh2wBXAGx+e592CRPkE9sMcTXbsuYACYBTAGYBLMEoXN5y9ZoXCk+Xao1bJp-Vpkc2AZQrwARiB7466GI5duPR0R9XdxpJIL8aWyA
💻 Code
const cmp = <T,>(x: T, y: T) => x < y
null < null
cmp(null, null)
undefined < undefined
cmp(undefined, undefined)
Symbol() < Symbol()
cmp(Symbol(), Symbol())
🙁 Actual behavior
Error messages:
- "The value 'null' cannot be used here.(18050)"
- "The value 'undefined' cannot be used here.(18050)"
- "The '<' operator cannot be applied to type 'symbol'.(2469)"
The errors show up for both operands of the relational operator except symbols, which only error on LHS.
The arrow fn cmp doesn't trigger any errors, even at call sites
🙂 Expected behavior
cmp should trigger an error on definition, because even though both params are same-type, they can't always be compared (symbols throw at runtime)
Additional information about the issue
No response
🔎 Search Terms
generics templates comparison compare less-than more-than unknown unsound function inline
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true&noUnusedLocals=true&noUnusedParameters=true&target=10&jsx=0&useUnknownInCatchVariables=true&exactOptionalPropertyTypes=true&noFallthroughCasesInSwitch=true&noImplicitOverride=true&noPropertyAccessFromIndexSignature=true&suppressImplicitAnyIndexErrors=true&ts=5.6.0-dev.20240619&noStrictGenericChecks=true#code/MYewdgzgLgBMC2AHGBeGAeAKgGgHwAoAPALhhxgE9TMBKVXGQjSgWACh2wBXAGx+e592CRPkE9sMcTXbsuYACYBTAGYBLMEoXN5y9ZoXCk+Xao1bJp-Vpkc2AZQrwARiB7466GI5duPR0R9XdxpJIL8aWyA
💻 Code
🙁 Actual behavior
Error messages:
The errors show up for both operands of the relational operator except
symbols, which only error on LHS.The arrow fn
cmpdoesn't trigger any errors, even at call sites🙂 Expected behavior
cmpshould trigger an error on definition, because even though both params are same-type, they can't always be compared (symbols throw at runtime)Additional information about the issue
No response