4 ms·
JS tried to add (optional) type hints in the ES4 standard that was never adopted (outside of tangential things like ActionScript 3). It would be great if Types
by WorldMaker 7y ago
JS tried to add (optional) type hints in the ES4 standard that was never adopted (outside of tangential things like ActionScript 3).
It would be great if Typescript hints could pass right along to the JITs as useful optimization factors, but it currently sounds like TC39 would prefer not to recreate the disasters of ES4 and are staying out of type hints for the forseeable future.
(Well-typed code should prevent most JIT bailouts, at least. Typescript linters could possibly give even better "shape" warnings than they currently do, such as catching the issue the React team recently found of bailouts in the V8 engine due to "shapes" being built with "small integers" being reallocated to doubles at runtime. However, such lint warnings would probably be JIT engine specific, and maybe premature optimization in 90%+ of usages.)
- _bxg1 7y agoYeah it's probably not worth it to add types to JS the language, but what if you could ship standard metadata files similar to source-maps that only included type information, which browsers could leverage to speed up compilation?
- WorldMaker 7y agoIn the long term, I hope that at least a compromise like the Python annotation approach could be reached (standardize the parsing, but ignore the semantics). Typescript type annotations share a surface level syntax with them in some ways, and also with ES4's type annotation attempt. "Type maps" are an interesting idea. You could probably piggy back on/boostrap from WASM types.
- tomcam 7y agoSounds good in theory, but it seems like rich territory for mismatched types in the source and map files.
- _bxg1 7y agoI don't see why that would happen; you wouldn't be writing these by hand
- z3t4 7y agoAdding types would probably slow down the code as some optimizations done by the engine wouldnt be allowed. Kinda like when you use bitwise operations for optimization only to find out they actually slow down the code. We could hower add Interface and optional types as syntax sugar for runtime checks.
- pjmlp 7y agoWhich is kind of ironic given WebIDL.