Live data from Hacker News

Node.js adds experimental support for TypeScript

github.com

41–50 of 570 posts

Re: Node.js adds experimental support for TypeScript

#41
post #13

Earlier quoted context omitted.

This reminds me of io.js situation, where in the end major fork changes were incorporated into Node. This is why I am comfortable staying with Node and npm for my projects - the features will eventually trickle down anyway.

But in the meantime you suffer for it. How many days have you spent on webpack config? Or the package.json type property? Or yarn/pnpm/etc particulars? I have spent too many. Bun is quite nice.

Very true, rising popularity of deno and bun clearly indicate that new runtimes solve real issues people have. That's why I mentioned "my projects", your experience may vary.

Re: Node.js adds experimental support for TypeScript

#42
post #23

Earlier quoted context omitted.

its about time google chrome started making a typescript engine maybe? and get rid of JS in phases?

There are a few optimizations that types can use but 99% of applications wouldn't benefit from them anyways.

Taking one link out of the toolchain (tsc) would already be a huge blessing.

And naive me hopes for a future where in my web-app I can set a policy that any non-ts, type-incompliant code is not allowed to run.

The amount of exceptions I get in the console from terrible garbage-code outside of my control but that I have to include because enterprise is staggering. Would love to have a meta-setting which would just kill them if they can't be arsed to even have a modicum of code-hygiene (sorry for the rant)

Re: Node.js adds experimental support for TypeScript

#43
post #32

Earlier quoted context omitted.

It is explicitly not type as comments, it is type erasure

> This proposal aims to enable developers to add type annotations to their JavaScript code, allowing those annotations to be checked by a type checker that is external to JavaScript. At runtime, a JavaScript engine ignores them, treating the types as comments.

Yes, that’s explaining what type erasure is. “type as comments” is what Flow supports, literal comments for type annotations.

I think we disagree on the terminology but agree on the goal of the proposal

Re: Node.js adds experimental support for TypeScript

#44
post #43

Earlier quoted context omitted.

> This proposal aims to enable developers to add type annotations to their JavaScript code, allowing those annotations to be checked by a type checker that is external to JavaScript. At runtime, a JavaScript engine ignores them, treating the types as comments.

Yes, that’s explaining what type erasure is. “type as comments” is what Flow supports, literal comments for type annotations. I think we disagree on the terminology but agree on the goal of the proposal

Types as comments is what jsdoc supports. Flow is compiled like typescript.

tsc does also support jsdoc though, so technically I think tsc is closer to supporting types as comments, though it's possible Flow has this also.

Re: Node.js adds experimental support for TypeScript

#45
post #4

My favorite deno feature is coming to node directly. Awesome! Maybe this means I don't always have to install esbuild to strip types - very excited how this will make writing scripts in TypeScript that much easier to use. I lately have been prefering Python for one off scripts, but I do think personally TypeScript > Python wrt types. And larger scripts really benefit from types especially when looking at them again a…

btw if anyone is looking to run ts on node, there is tsx. there is also ts-node but i prefer tsx. https://github.com/privatenumber/tsx

I second this. The tsx library is zero config and always "just works" in my experience, which puts it miles ahead of ts-node, imo.

Re: Node.js adds experimental support for TypeScript

#46
post #28

I'm honestly giddy. This could be the (slow) beginning of a new era, where "JS with types" is finally a native thing. I'm even willing to forgive all the mess that CJS vs. ESM is if they manage to pull this off. I hope this sees widespread adoption/usage, which might finally cause some movement to integrate TS into ecmascript after all. Some dynamically-typed language fanatics (which are, in my opinion, completely de…

Yeah, my personal experience is that easily 95% of devs I work with/have met in person, if not closer to 99%, prefer statically typed languages. Maybe that’s a biased sample, but I do think the overall preference among devs is very strong. I also see JS slowly, more-or-less becoming TypeScript over time.

Re: Node.js adds experimental support for TypeScript

#47
post #39
post #34

If Node.js can run TypeScript files directly, then the TypeScript compiler won't need to strip types and convert to JavaScript - it could be used solely as a type checker. This would be similar to the situation in Python, where type checkers check types and leave them intact, and the Python interpreter just ignores them. It's interesting, though, that this approach in Python has led to several (4?) different popular…

> In Python, I've even heard of people writing types in source code but never checking them This is my main approach. Type hints are wonderful for keeping code legible/sane without going into full static type enforcement which can become cumbersome for rapid development.

You can configure typescript to make typing optional. With that option set, you can literally rename .js files to .ts and everything "compiles" and just works. Adding this feature to nodejs means you don't even have to set up tsc if you don't want to.

But if I were putting in type hints like this, I'd still definitely want them to be statically checked. Its better to have no types at all than wrong types.

Re: Node.js adds experimental support for TypeScript

#48

Earlier quoted context omitted.

TypeScript used to have a standard. Years and years ago. Now it's whatever the compiler does. Which to be fair, is evolving quite rapidly.

Yeah, that was from 2016 or so. But a TypeScript spec is different than folding TypeScript into the ECMAScript standard. Some parts of TypeScript would have to be dropped or changed for that to work.

Right, having a spec is easier (and effectively prerequisite) to your suggestion.

But they don't have it.

Re: Node.js adds experimental support for TypeScript

#49
post #43

Earlier quoted context omitted.

> This proposal aims to enable developers to add type annotations to their JavaScript code, allowing those annotations to be checked by a type checker that is external to JavaScript. At runtime, a JavaScript engine ignores them, treating the types as comments.

Yes, that’s explaining what type erasure is. “type as comments” is what Flow supports, literal comments for type annotations. I think we disagree on the terminology but agree on the goal of the proposal

The proposal would explicitly treat supported type annotation syntax as comments in the grammar. It is definitely types as comments, even if it is also type erasure.

And it would apply to Flow’s type annotation syntax which is also not presently treated as comments, at least for the very large subset of that syntax which overlaps with the proposal.

Post reply on HN