News for hackers. Stuff that matters.
Re:Node.js adds experimental support for TypeScript by harshitaneja on Thursday July 25, 2024 @01:49AM (#41065110)
I really enjoy typescript and have been yearning for a typescript runtime but I can't help but laugh that I left java all those years ago to finally seek something a lot closer to java.

I guess we all just wanted java with JIT, more feature rich type system and gradual typing. Also for all the shortcomings of npm ecosystem, it is a lot less daunting and more fun to be using libraries in this ecosystem.

And surprisingly even though rust is on a different end of the language spectrum but yet it offers a similar feel.

Edit: JIT was not the right terminology to use. I lazily wrote JIT. Apologies. What I meant to convey was the difference in startup times and run time between running something in JVM and V8. Java feels heavy but in javascript ecosystem it feels so nimble.

Re:Node.js adds experimental support for TypeScript by qalmakka on Thursday July 25, 2024 @02:13AM (#41065243)
> we all just wanted java with JIT

Java was literally the thing that made the term "JIT" popular, so I really don't know what you were going for here.

Also I just can't see how Typescript is in any way "closer" to Java - it's incredibly different IMHO. The only thing they have in common is probably the "Javascript" misnomer and the fact both support imperative programming, but that's it.

Re:Node.js adds experimental support for TypeScript by seanmcdirmid on Thursday July 25, 2024 @02:28AM (#41065340)
Typescript’s optional and unsound type system also does nothing for a JIT beyond what it could already do for JavaScript, you can’t do optimization if your types are unreliable. However, I really really like how Typescript’s type system super charges developer productivity (type errors via the compiler and feedback via the IDE), and don’t mind this part of the design at all.
Re:Node.js adds experimental support for TypeScript by teaearlgraycold on Thursday July 25, 2024 @03:02AM (#41065570)
You can use typescript types to compile functions. You just might need to deoptimize when you actually hit the function.
Re:Node.js adds experimental support for TypeScript by seanmcdirmid on Thursday July 25, 2024 @11:58PM (#41075668)
I don’t know if Vortex-style compilation ever worked in practice.
Re:Node.js adds experimental support for TypeScript by bubblyworld on Thursday July 25, 2024 @02:05AM (#41065198)
I'm very glad to use typescript over java, personally - the ergonomics are so much better! Especially if you stray away from the somewhat incomplete classes thing (type support for decorator arguments isn't great, for instance) and just focus on interfaces and functions.

One thing I miss that java has is runtime reflection of types though. Typescript's ecosystem has a million different ways to get around that and they're all a bit ugly imo.

Re:Node.js adds experimental support for TypeScript by bufferoverflow on Thursday July 25, 2024 @02:02AM (#41065178)
Typescript is way better than Java, in my experience. It's a lot less verbose. A lot more flexible.
Re:Node.js adds experimental support for TypeScript by ZhongXina on Thursday July 25, 2024 @03:29AM (#41065789)
Better for what? Quickly churning out short-lived code to get the next round of funding, definitely. Writing (and _supporting_) "serious" projects over the long term, which also require high performance and/or high scalability, and can rip through terabytes of data if needed, definitely not. (All IMHO from lots of personal experience.)
Re:Node.js adds experimental support for TypeScript by viridian on Thursday July 25, 2024 @09:14AM (#41068308)
Depends on your architecture. For scaling out rather than up, node and python are both far more performant because the footprint of minimum viable environment is much smaller. When you need to serve anywhere from 10-200,000 requests a minute on the same system quickly, and efficiently, lambda/azure functions/google app engine backed by node or python is pretty ideal.

As an example, when my org needs to contact folks about potential mass shooter events, our SLA is 90 seconds. If we did it in cloud with java or .net, it'd be too slow to spin up. If we did it on prem, we'd be charged insane amounts just for the ability to instantly respond to low frequency black swan events, or it'd be too slow. This is a real story of how a Java dev team transitioned to using node for scale in the first place.

Re:Node.js adds experimental support for TypeScript by neonsunset on Thursday July 25, 2024 @09:50AM (#41068678)
Unlike Spring, JIT-based ASP.NET Core deployments spin up very fast (<2-5s for even large-ish applications, the main bottleneck is how fast it can open connections to dependencies, load configuration, etc.). For AOT variant, the startup time is usually below 200ms if we don't count the slowness of surrounding infra which applies to any language.

Of course CPU and RAM per request when compared to Node.js are not even close as Node is easily slower by a factor of 2-10.

Re:Node.js adds experimental support for TypeScript by hot_gril on Thursday July 25, 2024 @11:54AM (#41070105)
It's good for things that don't involve ripping through terabytes of data, which is actually a lot of things. And idk if I'd use Java for that either.
Re:Node.js adds experimental support for TypeScript by mcluck on Thursday July 25, 2024 @03:31PM (#41072441)
I'm actually in this exact position right now. The vast majority of the time I write in TS but I have a need to process a whole lot of data so I went for Rust instead. Java is too much of a headache for me, personally
Re:Node.js adds experimental support for TypeScript by hot_gril on Thursday July 25, 2024 @05:10PM (#41073430)
Yeah, Rust is fast, or you can go the other extreme with Python if you can put the heavy lifting on native modules.
Re:Node.js adds experimental support for TypeScript by sgammon on Thursday July 25, 2024 @02:35AM (#41065384)
They are not comparable. If anything, Kotlin is the equivalent in the JVM universe.
Re:Node.js adds experimental support for TypeScript by quonn on Thursday July 25, 2024 @03:22AM (#41065738)
Kotlin is much closer to Java than to TypeScript even in terms of flexibility.
Re:Node.js adds experimental support for TypeScript by DarkNova6 on Thursday July 25, 2024 @03:30AM (#41065792)
To me "Flexibility" sounds a lot like "The programmer always knows what he does".
Re:Node.js adds experimental support for TypeScript by scotty79 on Thursday July 25, 2024 @11:27AM (#41069804)
Flexibility means for me more something more like, I think I know what I want to do but I also know that I'm probably wrong about that, so for now let's skip all the baroque protocol and let me make it work first. Once I'm sure I wrote what I actually wanted I'll add types if only to get rid of some bugs, consider edge cases and earn nice code completions and auto-generated docs.
Re:Node.js adds experimental support for TypeScript by sgammon on Thursday July 25, 2024 @03:44AM (#41065904)
Sure, but Kotlin is to Java as TypeScript is to JavaScript, which is the point I am making.
Re:Node.js adds experimental support for TypeScript by wiseowise on Friday July 26, 2024 @05:02AM (#41076989)
That’s not even remotely true.

TypeScript is a direct superset of JavaScript. Any valid JS is a valid TypeScript.

If Kotlin is what TS to JS, then so is Groovy, Scala, Clojure and other JVM languages.

Re:Node.js adds experimental support for TypeScript by sgammon on Friday July 26, 2024 @03:29PM (#41081506)
> TypeScript is a direct superset of JavaScript. Any valid JS is a valid TypeScript.

Kotlin on JVM is a direct superset of Java on JVM. Any valid Java is also valid Kotlin at the bytecode layer.

> If Kotlin is what TS to JS, then so is Groovy, Scala, Clojure and other JVM languages.

Correct

Re:Node.js adds experimental support for TypeScript by sgammon on Friday July 26, 2024 @03:30PM (#41081510)
Laughs in `: dynamic`
Re:Node.js adds experimental support for TypeScript by zx8080 on Thursday July 25, 2024 @02:07AM (#41065210)
> we all just wanted java with JIT, more feature rich type system

Java has JIT. How is TypeSript type system feature-richer than the Java one?

Re:Node.js adds experimental support for TypeScript by wiseowise on Thursday July 25, 2024 @02:35AM (#41065378)
Re:Node.js adds experimental support for TypeScript by DarkNova6 on Thursday July 25, 2024 @04:07AM (#41066066)
> alone puts TS over anything that Java has.

Virtual Threads alone challenge this assumption.

Syntax bloat is not a feature.

Re:Node.js adds experimental support for TypeScript by Byamarro on Thursday July 25, 2024 @06:17AM (#41066853)
It's not really a syntax bloat, the linked docs mention how to define strict string types and elaborate on type-level programming, something that is a very rare and powerful type-level capability. As far as I understand Virtual Threads aren't type oriented feature, which is basically the context for this thread.
Re:Node.js adds experimental support for TypeScript by 3836293648 on Thursday July 25, 2024 @09:10AM (#41068267)
Virtual Threads are not a type system feature?
Re:Node.js adds experimental support for TypeScript by magnio on Thursday July 25, 2024 @03:03AM (#41065581)
I don't use them directly much, but template literal generic and contidiontal types is probably the closest a mainstream language has inched towards dependent types.

Some examples of TypeScript power:

- SQL database in TypeScript types: https://github.com/codemix/ts-sql

- Statically typed raw SQL queries: https://github.com/andywer/squid?tab=readme-ov-file#tag-func...

- (Someone fill in your TS hackery for me)

Re:Node.js adds experimental support for TypeScript by Vaguely2178 on Thursday July 25, 2024 @03:17AM (#41065686)
There are various programming language interpreters that run entirely in the type system:

- BF: https://github.com/susisu/typefuck

- Assembly: https://github.com/judehunter/ts-asm

Re:Node.js adds experimental support for TypeScript by VMG on Thursday July 25, 2024 @02:16AM (#41065269)
1. *Type Inference*: TypeScript can automatically infer types from context, reducing the need for explicit type declarations. 2. *Union and Intersection Types*: Allows combining multiple types, offering more flexibility in defining data structures. 3. *Literal Types*: TypeScript supports exact values as types (e.g., specific strings or numbers), which can be useful for more precise type-checking. 4. *Type Aliases*: You can create custom, reusable types, enhancing code clarity and maintainability. 5. *Interfaces and Structural Typing*: Interfaces allow for flexible contracts, and TypeScript uses structural typing, where the type compatibility is based on the shape of the data rather than explicit type declarations. 6. *Mapped and Conditional Types*: These allow for dynamic type creation and manipulation, making the type system more powerful and expressive. 7. *Optional Properties and Strict Null Checks*: These provide better handling of undefined and null values.
Re:Node.js adds experimental support for TypeScript by tpm on Thursday July 25, 2024 @02:34AM (#41065374)
That's just an copy-paste of some features, not a comparison with Java which does most of that too.
Re:Node.js adds experimental support for TypeScript by afiori on Thursday July 25, 2024 @02:43AM (#41065431)
Union types, structural typing, and conditional types are like a big chunck of what makes typescript typescript.

It is how TS is able to "type" a completely untyped language.

Just the support for union types is something that not even Haskell or Ocaml have.

Re:Node.js adds experimental support for TypeScript by nequo on Thursday July 25, 2024 @01:56PM (#41071439)
I am not familiar with TypeScript. Is there something that you can achieve with union types that you can’t with sum types or type classes in Haskell?
Re:Node.js adds experimental support for TypeScript by afiori on Thursday July 25, 2024 @03:03PM (#41072175)
TL;DR: Typescript is unsound so it can add a lot more type-level features that would make a sound type system undecidable

Conceptually no, almost every useful union type can be easily converted to a sum type. In my opinion the difference is in the ergonomics and in the implicit structural subtyping.

For example a common union type is number|string, and the beatiful part is that to use a value of such a type you do not need to do any matching or mapping you can just use the value as it does not have a runtime wrapper, for example (x:string|number)=>JSON.stringify(x) works perfectly fine.

Also you can have a function that takes as input a Array<string>|number|null and returns a string|number without having to declare different contructors for the input number type and the output number type

I believe that you can essentially implement this behaviour by generating enough typeclasses in Haskell, but regardless of the feasibility it, likely, would not be a good idea.

An example of something in between union types an Hindley–Milner sum types are Ocaml's polymorphic variants types https://ocaml.org/manual/5.2/types.html#sss:typexpr-polyvar that are (I believe) more advanced than TS unions but also a lot less ergonomic to use.

And TS has much more eg intersection types you could have a function with type

    (x:number)=>string & (x:string)=>number
meaning that it is both a function that maps number to strings and strings to numbers (again you can do this with typeclasses but it is a worse experience)

typescript also has very good support for value types for example there is the string type but also the "hello" type which is the type of only the string "hello"

All in all if someone told me that they implemented typescript in haskell typeclasses I would not call bullshit on them, but I would not believe that anyone would actually use it for anything

Re:Node.js adds experimental support for TypeScript by tpm on Thursday July 25, 2024 @03:25PM (#41072393)
> For example a common union type is number|string

So that's like my beloved Perl then.

Re:Node.js adds experimental support for TypeScript by VMG on Thursday July 25, 2024 @08:55AM (#41068119)
most of that? name one
Re:Node.js adds experimental support for TypeScript by tpm on Thursday July 25, 2024 @09:11AM (#41068279)
Java has type inference. Also if a type alias is just a new name for a existing type, then you can always do something like

  class MyNewClass extends OldClass {};
(of course it's not just a new name, it's also a new class, but it's also still a OldClass, and you are out of luck if OldClass is final or sealed)

Java also has interfaces, of course. And optional properties (using Optional) and strict null checks, when you want that, you can use it.

Re:Node.js adds experimental support for TypeScript by VMG on Thursday July 25, 2024 @09:51AM (#41068693)
> type inference

very limited, for instance you must declare the type of a public method

> alias

as you point out it's not

> Java also has interfaces, of course

but you have to implement them explicitly

> strict null checks, when you want that, you can use it

if we start accepting static analysis tools then C has null checks as well I guess

Re:Node.js adds experimental support for TypeScript by tpm on Thursday July 25, 2024 @10:59AM (#41069472)
> as you point out it's not

so what's the difference except the name?

> if we start accepting static analysis tools

I'm not talking about static analysis. In today's Java you can write code that does not accept nulls, if you want to.

Re:Node.js adds experimental support for TypeScript by svieira on Thursday July 25, 2024 @12:22PM (#41070468)
You cannot write code that will fail to compile `theEntryMethod(null)` unless you only use primitive types. (You can, of course, make that method fail at runtime, but that's not what's being talked about here).
Re:Node.js adds experimental support for TypeScript by guipsp on Thursday July 25, 2024 @09:50AM (#41068684)
Using optional still has the secret third thing problem
Re:Node.js adds experimental support for TypeScript by yen223 on Thursday July 25, 2024 @03:24AM (#41065753)
Java and Typescript have fundamentally different type systems, that lead to drastically different ways to approach types.

Utility types, like Partial<T>, are basically impossible to represent in Java except with almost-duplicated classes.

Re:Node.js adds experimental support for TypeScript by tpm on Thursday July 25, 2024 @08:57AM (#41068139)
> drastically different ways to approach types

Exactly.

> Partial<T>

Looking at that it's just what a default POJO (with nullable properties) already is, so I'd see no need to represent that in Java.

Looks cool though and I like Typescript; my issue with it is that it needs transpiling to run. If it was a first-class citizen in an environment I would use it for my pet projects.

Re:Node.js adds experimental support for TypeScript by crabmusket on Thursday July 25, 2024 @10:28AM (#41069072)
> it's just what a default POJO (with nullable properties) already is

I think you missed the point. Partial<T> is an example of a "mapped type", see the handbook for more explanation: https://www.typescriptlang.org/docs/handbook/2/mapped-types....

Re:Node.js adds experimental support for TypeScript by tpm on Thursday July 25, 2024 @11:01AM (#41069496)
I understand that much, just thinking aloud what problem would that solve in Java.
Re:Node.js adds experimental support for TypeScript by scotty79 on Thursday July 25, 2024 @11:39AM (#41069937)
I think it's for when you need type that expresses partial data update for an object that has some fields required.
Re:Node.js adds experimental support for TypeScript by svieira on Thursday July 25, 2024 @12:36PM (#41070617)
Yep - all non-primitive types in Java are `TheType | null` - TypeScript actually allows you to strip out the `| null`, which then means that sometimes you want to add it back in. So Java doesn't have a need for `Partial<T>`, it has a need for `NonNull<T>` and it can't express that at the type system level very easily right now (you can do it with type tagging and runtime checks inserted explicitly, but it's not very ergonomic right now)

https://gist.github.com/svieira/9f8beeafb7bf4aa55d40c638532f...

Re:Node.js adds experimental support for TypeScript by jddj on Thursday July 25, 2024 @02:56AM (#41065525)
I'm somewhere here as well. Personally I think what I want is the stdlib (without the current legacy/ all but deprecated bits) and ecosystem of c# but with the ease and power of structural algebraic types. AoT is fine, with option for single binary. Ideally runtimeless with clever trimming. If it also ran jitted in the browser all the better.

I also want compiler/type checker niceties like exhaustive pattern matching.

Re:Node.js adds experimental support for TypeScript by wiseowise on Thursday July 25, 2024 @02:40AM (#41065414)
> Also for all the shortcomings of npm ecosystem, it is a lot less daunting and more fun to be using libraries in this ecosystem.

God I wish they’d just integrate something lightweight like npm into JDK.

It is beyond me why you have to install third-party heavy weight tool just to manage dependencies.

Re:Node.js adds experimental support for TypeScript by dagenix on Thursday July 25, 2024 @01:59AM (#41065160)
Java does jit
Re:Node.js adds experimental support for TypeScript by harshitaneja on Thursday July 25, 2024 @02:10AM (#41065222)
Yes, JIT was not the right terminology to use. I lazily wrote JIT. Apologies. What I meant to convey was the difference in startup times and run time between running something in JVM and V8. Java feels heavy but in javascript ecosystem it feels so nimble.
Re:Node.js adds experimental support for TypeScript by sgammon on Thursday July 25, 2024 @02:36AM (#41065391)
Native Java via GraalVM starts up in milliseconds.
Re:Node.js adds experimental support for TypeScript by wiseowise on Thursday July 25, 2024 @02:42AM (#41065423)
And it has to go through slow compilation step. With Node you can have a cake and eat it too.
Re:Node.js adds experimental support for TypeScript by DarkNova6 on Thursday July 25, 2024 @04:13AM (#41066123)
You can't be serious about comparing the technological capabilities of the JVM and Node and objectively declare the latter as the winner.

Compilation times are also an absolute non-issue.

You don't compile for development. You do it for production (in the rare circumstances that you need it).

Re:Node.js adds experimental support for TypeScript by harshitaneja on Thursday July 25, 2024 @07:37AM (#41067356)
That's not what I am trying to convey here. JVM is amazing and it is a feat that java is as fast as it is and javascript and v8 are order of magnitude slower.

Also even though I also found java too verbose, I kept believing that we need it to be so to write good software. I still enjoy java but it doesn't compare to the ergonomics of typescript for me. And nimbleness of the experience according to me plays a decent role.

Currently for me, either I really care about performance and I default to rust for those applications or I need solutions where the product will evolve quickly over time and I need great DX over performance and I default to typescript for those.

Java definitely has a role to play but its role in my work has certainly diminished.

Re:Node.js adds experimental support for TypeScript by ZhongXina on Thursday July 25, 2024 @03:39AM (#41065865)
You're saying it like it's an absolutely good thing. Some (many?) users would rather pay the cost upfront in compilation time (doesn't really matter if it's AOT or JIT) than pay the same cost many times over through a significantly slower runtime. JVM also scales up to supercomputers (and everything in between) if you want it to, so depending on your requirements a single-threaded alternative might not even be an option.
Re:Node.js adds experimental support for TypeScript by wiseowise on Thursday July 25, 2024 @03:49AM (#41065947)
I’ll use C++ or Rust for such use cases.
Re:Node.js adds experimental support for TypeScript by sgammon on Thursday July 25, 2024 @04:26AM (#41066208)
Okay!
Re:Node.js adds experimental support for TypeScript by sgammon on Thursday July 25, 2024 @04:39AM (#41066301)
It does not "have" to go through such a step, by the way, because you can simply run such code on the JVM.
Re:Node.js adds experimental support for TypeScript by tomjen3 on Thursday July 25, 2024 @03:33AM (#41065818)
The typesystem of Java was so laughably unpowerful that it severely constrained what you could write.

In Typescript you have far more freedom, and all the benefits of strong types.

Re:Node.js adds experimental support for TypeScript by DarkNova6 on Thursday July 25, 2024 @04:14AM (#41066130)
Strong types without strong typing that is.
Re:Node.js adds experimental support for TypeScript by yen223 on Thursday July 25, 2024 @08:47AM (#41068034)
The fact that Java forced you to write types, and then made everything implicitly nullable so that you still get NullPointerExceptions at runtime after writing out all those types, was probably a big reason why dynamically-typed languages became popular.
Re:Node.js adds experimental support for TypeScript by ninepoints on Thursday July 25, 2024 @02:07AM (#41065211)
Not having an opaque tech stack encumbered by a patent minefield is another plus.
Re:Node.js adds experimental support for TypeScript by 38 on Thursday July 25, 2024 @02:13AM (#41065244)
> gradual typing

AKA dynamic typing. Unless it's 100% static, it's dynamic

Re:Node.js adds experimental support for TypeScript by debugnik on Thursday July 25, 2024 @07:05AM (#41067154)
Gradual typing could still keep some static guarantees if the static part were sound, e.g. you couldn't assign a dynamic-typed integer to a string-typed variable without checking the type at runtime first; which TypeScript isn't.

Elixir's new type system does much better here, as it determines whether a function actually guards for the right type at runtime ("strong arrows") and propagates the guarantees, or lack thereof, accordingly.

Re:Node.js adds experimental support for TypeScript by lmm on Thursday July 25, 2024 @04:19AM (#41066163)
Java's type system was just very limited, gradual typing is a poor tradeoff most of the time. I used to think there were advantages to something like Python, but once I found Scala I never went back.
Re:Node.js adds experimental support for TypeScript by scotty79 on Thursday July 25, 2024 @11:19AM (#41069710)
Gradual typing is the key. The problem with Java is that types are in your face way before you actually need them.

With TS you can prototype with JS and only after you know what you are looking for you can start to add types to find bugs and edge cases and want to get nice code completions for your stuff.

Re:Node.js adds experimental support for TypeScript by hot_gril on Thursday July 25, 2024 @11:55AM (#41070122)
The type system is a big part of what made Java cumbersome. It's loosened up a little over the years. TS itself may allow partial typing, but when team/company policies are involved, you'll often end up being forced to type everything.
Re:Node.js adds experimental support for TypeScript by austin-cheney on Friday July 26, 2024 @07:40AM (#41077781)
> I guess we all just wanted java with JIT

Oh god no. What an abomination.

Greater than 95% of the incompetence in JavaScript comes from two camps. The first of those are people who absolutely cannot program at all. The second of those are Java developers who were taught Java in school and it’s all they can do, so everything must look like Java.

The result of both tribes is pretending to do something they cannot do on their own. When you’re a pretender vanity becomes excessively important because everything is superficial, so you get layers of shit you don’t need that they cannot live without. Any attempts slice off the unnecessary bullshit always results in hyper emotional distress because people feel threatened when exposed. That right there is why I will never write JavaScript for employment ever again.