There's no need to have a restricted Javascript. All you have to do is to write code in ES6 with the type annotations and the entire program will be fully type-inferable (tho the inferring part may take a while because you probably need to do something like a Cartesian product for duck typing). Once you do that, you can do a lot of optimizations.