codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Automatically typechecking imports #44

Closed 0rvar closed 9 years ago

0rvar commented 9 years ago

I'd love it if undefined imports would cause a build/runtime exception rather than causing a timebomb to find later on. Is this possible to implement?

import Foo, { bar} from './foo';

turns into

import Foo, { bar } from './foo';
if(typeof(Foo) === 'undefined') {
  throw new TypeError(`'Foo' default import from './foo' is undefined`);
}
if(typeof(bar) === 'undefined') {
  throw new TypeError(`'bar' import from './foo' is undefined`);
}
pillowsoft commented 9 years ago

Use this: https://github.com/dozoisch/babel-plugin-import-asserts

phpnode commented 9 years ago

Yeah this is a pretty common bug, we could add support for it but probably needs to be configurable.

0rvar commented 9 years ago

@pillowsoft Thank you!