-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is empty tuple / record falsy? #380
Comments
I’d expect it to be truthy, since every container in the language is truthy when empty. Being a primitive would mean it could be falsy, of course, but I’m not sure that’d be useful. |
The non-empty equality tests ( |
The specification can be found in the ToBoolean abstract operation. |
I would expect is as falsy:
|
If empty is falsy, what value does this additional difference generate? I can't image when any code I seen try to check specially whether there is keys in an options object. And tuple's length should be easy to check. Expanding falsy value list should be very careful and necessary, as many type guard of existing libraries may relax their vigilance against false values. BigInt At least, I think only empty tuple could be falsy, but not record. But again, I think there will be many user pass tuple and record to lib api which only know array and object instead of them. Think about below: export function lib_api_2 (allows) {
if ( !allows ) { allows = [ 'defaultAllow' ]; }
}
export function lib_api_1 (options) {
if ( !options ) { options = { defaultFeature: true }; }
} |
This proposal has already established the following design goal: to allow generic functions to generically take arrays or tuples (see “Why are Record & Tuple not based on .get()/.set() methods like Immutable.js?”). As @LongTengDao’s example demonstrates, making If you want to allow generic functions that would treat arrays and tuples equivalently, and if |
For old codes that not designed to work with immutable object (aka, records), any behavior you have chosen would definitely not working. As you cannot assign If you try to feed an API which require And for newer codes, you can simply use default parameter or |
Hello, I was wondering if there's been any update about this. looks like !!#[] === true? |
I have not find any specification about the truthy / falsy about the tulpe or records. I had tested the playground and it currently report
!!#[]
and!!#{}
astrue
. However, I would expect it as falsy just like whatassert(!!"" === false)
do. Is this something not decided yet or could anyone point me a link to the previous discuses?The text was updated successfully, but these errors were encountered: