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

Are objects in class constructors supported? #12

Closed bebraw closed 9 years ago

bebraw commented 9 years ago

The plugin works perfectly with functions. Unfortunately I ran to a glitch with class constructors. To keep it simple I have a declaration like this:

export default class Lane extends React.Component {
  constructor(props: {
    name: string;
    i: number;
  }) {
  ...
  }
}

If I pass something else than string as a name, it doesn't fail as I expect. I know flowcheck can deal with this case but I'm actually looking at your tool as a replacement.

You can find a runnable example at https://github.com/survivejs/webpack_react/tree/typecheck-glitch .

Let me know if you need further information.

phpnode commented 9 years ago

This should now be supported, it wasn't related to constructor functions, we just didn't support that kind of object syntax, now we do :)

bebraw commented 9 years ago

@phpnode Thanks a lot! This worked very nicely. Is there any compelling reason to use flowcheck anymore?

phpnode commented 9 years ago

yes, flow can catch a lot more errors before the program actually runs whereas our static analysis is very rudimentary. They complement each other.