Hacking typed javascript
arjunguha edited this page Aug 16, 2010
·
1 revision
- Use the
-noflows
command-line option to disable flow analysis. If you’re hacking the type-system, interactions with flow analysis may be a distraction.
Similarly, use the-pretc
command-line option to skip type-checking and instead pretty-print the AST annotated withtagcheck
expressions.
- To test with a union-typed expression, you need to use functions:
function(x) /*: Int + Str -> Int */ { if (typeof x === "number") { return x; } else { return x.length; } }
The following variant will not work:
var x = /*:upcast Int+Str*/"dummy-string"; if (typeof x === "number") { return x; } else { return x.length; } }
Above, flow-analysis will determine that the else-branch is unreachable and the type system will signal an error.