I wish there was a way to write const [A, B] = fn(), and inside fn() write return [A, B], and have @flowtype fail on “name” mismatches.
-
-
I think the OP's goal were lost in this thread.
@dan_abramov wanted to avoid bloating the bundle with the full property names. (That might be an artifact of a poor metric.) You can use numeric properties in a typed object though. -
I'm not up to date on the TypedObjects stuff, but I would be in favor as long as they don't have value type semantics, and support numeric index access without penalty.
-
It's the "without penalty" that is tricky with JS VMs. Unless you make it very explicit, you can't rely on the optimizations you want happening. :( E.g. OCaml is not value types because it is semantically free to do those optimizations anyway. JS VMs wouldn't in most cases.
-
Even things like multiple return values that could be optimized in theory if both sides are known, is something we can't rely on. Making that an explicit desire in the API (e.g. through value types) makes that more likely. Maybe there's another way to achieve that though.
-
I accept the reality that in a VM, typed objects without value semantics must accept some tiny penalty. (I was merely saying that numeric indices should note receive additional penalty (not that anyone would go out of their way to penalize them!))
-
Coming back to this - I think that TypedObjects proposal was very large and has a ton of stuff I can't imagine being immediately useful (I wonder what the original use case was). Is it worth reviving this in limited form:
-
- Simple object/array like structure with very few features and no/low prototype. - Not extensible - cannot add or delete fields. - Users must preresolve fields to integers at creation and access time. - The runtime types of individual fields can't / don't need to be modeled.
-
Basically TypedArray but whose contents are not typed, heterogeneous, and treated as a single 64bit number which in many VMs would be its standard NaN-boxed representation of any "normal" JS value. Not sure how that would work in Chrome though.
- 3 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.