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