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

Param assignment tracking #153

Closed ghost closed 7 years ago

ghost commented 8 years ago

Is it possible to keep track of type of a function's argument inside the function's body?

foo('bar')

function foo(str: string) {
  str = 12 // should be an error
}
phpnode commented 7 years ago

Hi, sorry for taking so long to respond to this, this project is now deprecated in favour of https://codemix.github.io/flow-runtime which aims for full compatibility with Flow.

I checked and babel-plugin-flow-runtime does not have this particular bug, it transforms the code to:

import t from "flow-runtime";
foo("bar");

function foo(str: string) {
  let _strType = t.string();
  t.param("str", _strType).assert(str);
  str = _strType.assert(12);
}