Skip to content

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

@wchargin

Description

@wchargin

Consider the following two files:

dep.js

// @flow
export type Fruit = string;  // doesn't matter

test.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:

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

{"presets": ["babel-preset-flow"], "plugins": ["babel-plugin-flow-react-proptypes"]}

package.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"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions