brigand / brigand/babel-plugin-flow-react-proptypes

Types imported with `import *` (import star) are treated as values, causing runtime error

Open
#201 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
427
Forks
42
PR merge metrics
No merged PRs in 30d

Description

Consider the following two files:

**dep.js**
```js
// @flow
export type Fruit = string; // doesn't matter
```

**test.js**
```js
// @flow
import * as Dep from "./dep.js";
export type Fruit = Dep.Fruit;
```

These files type-check (`yarn flow check`) without problem.

But the output of `npx babel test.js` is the following:

```js
import * as Dep from "./dep.js";

var bpfrpt_proptype_Fruit = function () {
return (typeof (Dep.Fruit == null ? {} : Dep.Fruit) === "function" ? PropTypes.instanceOf(Dep.Fruit == null ? {} : Dep.Fruit) : PropTypes.any).apply(this, arguments);
};

import PropTypes from "prop-types";
export { bpfrpt_proptype_Fruit };

```

It is a runtime error to refer to `Dep.Fruit`, because that export only
exists at the type level.

**.babelrc**
```json
{"presets": ["babel-preset-flow"], "plugins": ["babel-plugin-flow-react-proptypes"]}
```

**package.json**
```json
{
"name": "demo",
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-plugin-flow-react-proptypes": "^24.0.1",
"babel-preset-flow": "^6.23.0",
"flow-bin": "^0.75.0"
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.