hegel
hegel copied to clipboard
Relational operations should inferred for string as well
function le(a, b) {
return a <= b
}
Actual:
a
and b
infer as $StrictUnion<bigint | number>
Expected
a
and b
infer as $StrictUnion<bigint | number | string>
Actually, Should it have a behavior like this? In this case, strings will be cast implicitly into char codes for the comparison. One of the Hegel.js design goals is to avoid implicit type casts for predictability and type safety. But, I'm not sure, that we should avoid those kinds of typecasting. So I want to discuss it here.
"a" <= "b", "a" == "a", "a" != "b" and etc is fully valid binary operations for strings and doesn't required any implicit casts.
Real world example:
const arr = [{ key: "b" }, { key: "a" }];
arr.sort((a, b) => Number(a.key > b.key) - Number(a.key < b.key)) // Number(op) need for explicit cast from Boolean to Number