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

Conditional comment to ignore syntax? #54

Closed STRML closed 8 years ago

STRML commented 8 years ago

Thanks for the great work on this plugin.

As I convert my project to Flow, I've been noticing some incompatibilities between the two libraries.

Some of this is because I am still stuck on Babel 5 / Typecheck 2.0.0 due to react-transform not yet releasing a Babel 6 plugin.

For example, the following definition is valid Flow but throws in plugin-typecheck:

function(symbol: string): [?number, ?string] { /* ... */ }

The error is:

SyntaxError: Unsupported annotation type: TupleTypeAnnotation

For now I have commented the line, set the type to any and put a big FIXME on it until I am able to update to the newest typecheck lib. But in case this happens again in the future (and I assume it will, as Flow receives new features), is there a way for us to get typecheck to simply ignore a line?

phpnode commented 8 years ago

@STRML typecheck should never throw on syntax that it doesn't understand for exactly this reason, so the behaviour you're seeing is definitely a bug and maybe it's worth updating the 2.x branch. In 3.x it will simply ignore the annotation. Arguably we should add a mode which warns when we see this stuff, but we should never prevent the programmer from using it.

phpnode commented 8 years ago

To add, we could definitely consider adding pragmas in comments in a similar fashion to jshint ignore: line etc.

STRML commented 8 years ago

Both sound good to me. There's always the risk that new Flow syntax will expand old, leading typecheck to misunderstand existing syntax. So the comments would be a big help.

STRML commented 8 years ago

Thanks! This is a big help.