However, I just found an unbelievable JS bug that is on Safari and Chrome. If you are writing some JS, so look out for this one:
lets say you have a standard library module and it defines some functions and constants. But FOOBAR isn’t one of them.
import * as std from './stdlib.js’; let z1 = FOOBAR; // compiler finds this error, FOOBAR the local name is not defined yet let z2 = std.FOOBAR; // this is a valid module name, but not a known symbol inside the module std, compiler lets it slide let z3 = stx.FOOBAR; // compiler catches this error, module name was misspelled.
If you make a typographical error and import a symbol that doesn’t exist, perhaps because you made a small spelling error, the compiler doesn’t catch the undefined name, and treats it like a property that doesn’t exist, which it is not. They forgot that a module name prefix is not an object, and that all imported symbols must be found.
This is a massive error in both Chrome and Safari, i can’t believe they didn’t catch this. It is most unfortunate that the folks at Google and Apple didn’t spend more time with Ada or Modula-2, which not only had modules but separately compilable modules, something that JS doesn’t have. Frankly you cannot have interchangeable parts without separate compilation. I wonder how progressive web apps are going to work completely without addressing some of these issues.
This makes modules incredibly dangerous compared to one big glob of code. The whole point of modules is to split namespaces so you don’t accidentally use a variable that isn’t part of your region of code, so this is tantamount to sabotage of the module system.
Writing in Actionscript 3 you get a very solid compiler and toolchain, and AS3 and JS are so close now, you can convert one to the other with mostly just a series of find/replace operations in a text editor. Instead of using TypeScript, i suggest you try Actionscript 3 which retains the type information at runtime, and use AS3 for your mobile and desktop targets, and then convert to JS using a simple script to run in the web. This way you get good protection. TypeScript can't carry the checks into runtime.