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

Union of literals #55

Closed sgodwin424 closed 8 years ago

sgodwin424 commented 8 years ago

With the following code:

type EnumType = 't1' | 't2';

function f(b: EnumType) {
}

f('t3');

I don't receive a warning using Flowtype. Using it with this plugin, it is transformed into a function that simply checks that the given variable b is of a type of one of the literals in the EnumType. I think it should not just check for the type when the type alias is using literals but also compare it to the given values.

Based off of reading some of the Flowtype issues, unions are the only way of defining enums currently.

phpnode commented 8 years ago

Yep, we currently treat let foo: "some string" as if it were let foo: string. Will fix that in the next release.