3 ms·
I'm not sure I understand the concern. Static types are checked and emit errors, but they do so statically (i.e. at compilation time). There's nothing I see in
by shadowgovt 4y ago
I'm not sure I understand the concern. Static types are checked and emit errors, but they do so statically (i.e. at compilation time).
There's nothing I see in this proposal to prevent a user-agent from running a static analysis on JavaScript input into the console or DOM editor before trying to interpret it. If what you're saying you want is for the typechecking to be done by the user-agent for every piece of downloaded JavaScript... Why? I mean, a user-agent could be constructed to do that, but it'd be inefficient over just trusting the vended code (which, in a sense, we should probably just default to doing, because nothing stops the developer from type-asserting or omitting types so in the grand scheme of things, the code is exactly as provably sound if we typecheck it before running as if we don't).
What would "actual static typing in JavaScript" look like that this proposal isn't?
- asddubs 4y agothe proposal is for type annotations, which are to be treated as comments. i want type checking to be done in the browser, whether it's before the javascript is run or at runtime isn't important, the point is that i want the browser to explicitly be forced to do it. and then if I'm sure my types are correct and I want to speed things up, I can strip out the type annotations. but this means that for smaller scripts, or in general during development, you don't need an extra compilation step at all. I want the browser to reject feeding a string into a number parameter of a function, at which point it does this isn't important to me as much as that it should be more than just a comment that is ignored completely.
- shadowgovt 4y agoIf it's static analysis, then the browser can always execute it and throw it out after execution, that's the nature of static analysis. There would absolutely have to be an escape hatch, or configuring one's browser in this way would make most of the web fail to work (and unfortunately, the golden rule for features in browsers is "if it breaks most existing sites, you can't add it because most users aren't savvy enough to understand what is happening and will uninstall your browser in response"). But I can't actually see anything stopping a given user agent from choosing to offer that as a development feature for a specific domain, which would be pretty swell.