Hacker News new | ask | show | jobs
by jchw 3256 days ago
I wish we could take the best of AS3, ESNext, and TypeScript, and make it into one WebAssembled language...

Well okay. That's insane. But there's a part of me that wants to know how far it would go.

3 comments

That's basically Haxe, if/when it adds a WebAssembly target. It already supports regular JS.

www.haxe.org

We're basically waiting for the spec for GC to come together and early betas to hit the repo. Support for the WebAssembly target will come soon after. https://github.com/WebAssembly/gc/blob/master/proposals/gc/O...

Follow haxe.io for news, etc. : https://haxe.io/

I like Haxe but had my qualms with it too. To be honest, I would have to try again, but last I tried I remember at least having some issues with the type system, and the module system was OK but I definitely miss my ES modules.
Maybe not all that insane, but TypeScript is already essentially what you're describing.
TypeScript is typechecked only at translation time, as is reasonable for any language you would compile to JS. (I guess Elm breaks this mold, but at some great costs.) A side-effect is that you don't have any type information at runtime, for example.
This isn't as bad as it sounds in practice. I'm usually glad it eliminates reflection which I've rarely seen used honorably... I do miss it occasionally.

Some popular typed languages, notably Java, do type erasure on objects as well. Extending that to value types feels right in a strange way, more consistent at least.

One thing I'll mention to make The a better experience... The compiler, even on the strictest options, will still let you do a lot of hacky old school JS crap. I HIGHLY recommend integrating TSLint with almost all rules turned on and Microsoft's contrib extension. It makes Typescript code almost bulletproof.

Use the Typescript language service and experimental plugin for VSCode to show both Typescript errors and TsLint errors live with intellisense. It's a pain to set all this up at first but the experience is slick.

On that note I wish tslint would stop trying to do code formatting rules. prettier nowadays does code formatting far better than tslint ever did.
I thought Prettier didn't support TypeScript, as the TS AST is completely different to the JS AST.
It's not very different; Typescript strives to be a JS superset.

Anyhow, it does support it just fine. Even tsx/jsx (react-extended js/ts).

:-) same here. Those are the few rules I shut off. TsLint really shines in static analysis.
Check out flow-runtime [0] [1]. I've only poked around with it, but it seemed solid.

It supports pragmas so you can turn off assertions in production everywhere except in critical files.

[0] https://github.com/codemix/flow-runtime

[1] https://codemix.github.io/flow-runtime/

Isnt JS/ES approaching this? + the native stuff
More or less yeah. But I worry it will take a pretty big change in direction before we can get something as crazy as types in the browser. To be fair, I would have never guessed browsers would be able to implement the current standards to the degree that they have.
It's probably worth remembering that AS3 was essentially based on the draft (later abandoned) ES4; there's still a vague agreement that most of those features should come back.