flow-runtime-cli doesn't output type aliases
This is a:
- [ ] Bug Report
- [ ] Feature Request
- [X] Question
- [ ] Other
Which concerns:
- [X] flow-runtime
- [ ] babel-plugin-flow-runtime
- [ ] flow-runtime-validators
- [ ] flow-runtime-mobx
- [ ] flow-config-parser
- [ ] The documentation website
What is the current behaviour?
(This is similar to #69 but, TBH, I don't understand what the problem was and flow-runtime-cli didn't produce any output for me. If there are some docs that describe what's happening, please point me in the right direction.)
When running the following code:
import axios from 'axios';
import type {AxiosPromise} from 'axios';
const request: AxiosPromise<any> = axios.get('https://google.com/');
...this message is printed to the console:
flow-runtime: Failed to reveal unknown type in Temporal Dead Zone.
Can you help me understand what this means and what the right fix is?
What is the expected behaviour?
No message appears.
Which package versions are you using?
{
"dependencies": {
"axios": "^0.16.1",
"babel-cli": "^6.24.1",
"babel-plugin-flow-runtime": "^0.11.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"flow-bin": "^0.47.0",
"flow-runtime": "^0.12.0",
"flow-runtime-cli": "^0.12.0",
"flow-typed": "^2.1.2"
}
}
It happens because flow-runtime cannot resolve that type, are there any type definitions for AxiosPromise? If so flow-runtime-cli should be picking them up
Thanks for the quick response. The type definition is installed from flow-typed. If I change the file like this:
// @flow
import axios from 'axios';
import type {AxiosPromise} from 'axios';
const request: AxiosPromise<any> = axios.get('https://google.com/');
request.then((response) => {
console.log(response.DOES_NOT_EXIST);
});
Flow detects the error:
$ node_modules/.bin/flow
src/test.js:9
9: console.log(response.DOES_NOT_EXIST);
^^^^^^^^^^^^^^ property `DOES_NOT_EXIST`. Property not found in
9: console.log(response.DOES_NOT_EXIST);
^^^^^^^^ AxiosXHR
Found 1 error
But I still get the same console output when I run it:
$ node_modules/.bin/babel src/test.js | node
flow-runtime: Failed to reveal unknown type in Temporal Dead Zone.
undefined
And I get the same message with flow-runtime-cli:
$ ./node_modules/.bin/flow-runtime generate src
flow-runtime: Failed to reveal unknown type in Temporal Dead Zone.
Need to figure out why flow-runtime-cli isn't picking it up, which version is coming from flow-typed? Presumably https://github.com/flowtype/flow-typed/tree/master/definitions/npm/axios_v0.16.x ?
It will be a while before I have time to look into this myself, but if you fancy digging into the details I'd gladly accept a PR.
Okay, good to know that the correct behavior is for flow-runtime-cli to pick it up. I'll see if I can take a look in the next few days.
And yes, I installed the definitions for Axios 0.16.
Oh, by the way, I think that "Failed to reveal unknown type in Temporal Dead Zone" error message is a red herring. It happens even when I run flow-runtime on an empty file. It seems to be related to runtime checks on flow-runtime itself when it's calling into minimist to parse the args.
I'm not sure that I know enough to fix this. But I noticed that the AST for the Axios library definition has TypeAlias nodes for the declare type lines:
https://astexplorer.net/#/gist/8b8e67cb3d55ae731e26a03218a0611e/37c7cba991d91f865098ea1f97ff89964735ce75
And if I change this line:
https://github.com/codemix/flow-runtime/blob/acc4e3608008d17a4157521664068e99939912ff/packages/flow-runtime-cli/src/importAST.js#L63
To say || path.type === 'TypeAlias', then the flow-runtime command generates output. I don't know if this is the right fix though. Is this enough for you to go on?
My cli outputs absolutely nothing when i try even though I have tons of flow-typed files available.It also does not pick up the core libraries for things like react and the core js objects so I can't even use Promise or Iterator etc without errors