-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Requesting clarification on the "correct" export(s) of immutable.js #863
Comments
In the current versions I'm running- flow
results in a "This module has no default export" error, whilst
runs fine. I guess that decides the issue, then? I have never had any issues using |
I believe this should fix it: #961 |
@ccorcos: The issue is a little more nuanced than just missing Flow definitions for a default export. There are huge semantic differences between named and default exports. However, transpilers blur the line because (depending on the implementation), among other reasons, they allow you to treat a module of named exports as a single default export. Right now there are multiple inconsistencies:
Correcting this is trivial, however, a decision must be made about what is the "correct" export of Immutable. The options are: (A) Only a default export of an object with everything on it. Once one is picked, all of the inconsistencies can be fixed. Your PR (#961) is making the decision that (C) is the way to go. Fine. But then the PR is incomplete because the implementation ( |
I worry that this also hasn't quite solved the issue raised above: "This seems a bit odd since many of the exports correspond to common globals. So to avoid shadowing globals (and creating confusion when seeing Map buried deep in code), one would have to use Immutable like this:
" I feel like this current solution makes it very easy to abuse this to write code that obfuscates code through shadowing globals. Perhaps the better solution might be (A) simply because it makes it more difficult to write bad code. That being said, being forced to import everything isn't necessarily best case either. |
Interesting... I didn't realize theres an ambiguity around At the very least, I think the flow type definition should represent the codebase (otherwise the type checker doesnt work!). I can change that in the PR. But as a general discussion, I think destructuring the default export when you import is probably not a good idea. But the |
IMHO the standard way to use with ES6 imports should be: import {Map, fromJS} from 'immutable';
// or
import * as Immutable from 'immutable'; |
however it would be nice for convenience to also export an ES6 default such that import Immutable from 'immutable'; Also continues to work correctly. That might mean a slightly more awkward flow definition file, but that would enable those who use it this way currently to keep doing so without breakage. |
Both are now implemented in master and will be released soon |
This is more of a general question than anything specific to immutable, but is there a way with es6 or typescript to do an import of just the exports we need, but still have them namespaced? This doesn't actually work, but something like this:
|
I understand that since Immutable is transpiled, much of this is a fiction. I'm only looking for "correctness" because flow isn't as forgiving.
The module entry exports only a
default
, implying that the correct usage of Immutable is:However, the flow definition exports each data structure and helper function as a named export. Implying that the correct usage of Immutable is:
This seems a bit odd since many of the exports correspond to common globals. So to avoid shadowing globals (and creating confusion when seeing
Map
buried deep in code), one would have to use Immutable like this:So which is correct? The module entry or the flow definition? Or can we have both- Can Immutable export both a default and named exports?
Other discussions: #854 and #855.
The text was updated successfully, but these errors were encountered: