Babel/types/fix/export flow types#11671
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/24996/ |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b153d07:
|
That error seems correct, since |
Your recommendation is in plain JS and suggests to import all the exported JS values of a module, but I'm trying to import the exported default type of a JS module as a Flow type. In Flow, that's done like this: Hence why I needed to do some of the changes in this PR. |
|
🏓 |
|
? import typeof * as t from "@babel/types" |
Summary:
For some strange reason, importing babel types with the syntax `import typeof * as BabelTypes from 'babel/types'` causes Flow errors to appear.
But if we use `import typeof as BabelTypes...` instead, it works as expected.
```
$ /oss-fbt/__github__/node_modules/.bin/flow check --show-all-errors
Error -------------------------------------------------------------------- flow-types/nonfb/libdef/babelTypes.js:1806:18
boolean [1] is not supported by unclassified use SubstOnPredT.
flow-types/nonfb/libdef/babelTypes.js:1806:18
1806| declare export function isArrayExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeArrayExpression)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
References:
flow-types/nonfb/libdef/babelTypes.js:1806:94
1806| declare export function isArrayExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeArrayExpression)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
Error -------------------------------------------------------------------- flow-types/nonfb/libdef/babelTypes.js:1807:18
boolean [1] is not supported by unclassified use SubstOnPredT.
flow-types/nonfb/libdef/babelTypes.js:1807:18
1807| declare export function isAssignmentExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeAssignmentExpression)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
References:
flow-types/nonfb/libdef/babelTypes.js:1807:99
1807| declare export function isAssignmentExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeAssignmentExpression)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
...
Found 238 errors
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```
Repro steps:
```
yarn
yarn clean-test
# run yarn flow:check or flow:watch to run Flow checks again afterwards
```
Issue related to: babel/babel#11671
Differential Revision: D22032614
fbshipit-source-id: d6c6663cd8e7a812759ef1b5ce7a80324bb1ba44
|
I tried E.g. from fbt project: facebook/fbt#150 There seem to be a problem using I've asked the Flow team for help; in the meantime, do you reckon the current solution in this PR is good enough for now? |
|
Ping @nicolo-ribaudo The Flow team will fix the type issue mentioned above. What do you think about the rest of this PR? |
|
🏓 |
|
@kayhadrin Can you rebase on |
ee4bb1c to
aade6dd
Compare
Done. |
|
@kayhadrin Please run |
aade6dd to
b153d07
Compare
|
Ok, rebased again on the |
|
@JLHwung 🏓 |
(sorry, I didn't mean to approve yet)
|
Just to understand, the |
Yes, it used to work but some other Flow type changes caused it to break (e.g. the addition of
TBH, unless we're prepared to patch older Babel releases, I think I could already remove the |
|
@nicolo-ribaudo What would you like me to do then? |
|
Thank you for your PR! Since it is now obsolete, I will close it. |
To properly import
@babel/typestypes in a Flow+JS project, we need to fix a few things:@babel/typesmodule exports a default value; otherwise, we'll get a Flow error that sounds like "cannot import a default export because there is no default export"@babel/typesmoduleNode->BabelNode@flowpragma in the file header. It's not mandatory, but it helps in some scenarios when we want to import theindex.js.flowfile directly.Generated output example: https://gist.github.com/kayhadrin/dfe0f9785622a1dfaf726cba0001b993