Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How so? It looks a lot like a less-rich Java, whose type system has existed for literally decades. In fact, the generics syntax and type erasure was directly influenced by Java.


Typescript has far more powerful type constructs than Java.


Such as?



Quite nifty, but I still wouldn't call it far more powerful. Take a look at https://checkerframework.org/ for example.


I haven’t used Java in many years, but TypeScript’s structural types give it a different flavor than I remember from Java. Unlike in Java, most of the types I define aren’t classes or interfaces. It’s just data that has an expected shape.

Check out the design of Zod, for example. I have a bunch of Zod types for the validation of incoming JSON messages. This automatically generates the corresponding TypeScript types through the magic of type inference.

It’s quite easy to create discriminated unions, which are just structs where one field has a fixed value.


In functional programming, a type is just a function that returns a list of possible values. It’s not a class.


> In functional programming, a type is just a function that returns a list of possible values

Its literally not; there may be a language which does this or something close (actually, I’ve seen narrow, purpose-focussed relational languages where this is the case, and all types are enumerable), but it's definitely not generally the case in functional languages.


Conceptually, you can think of a type as a set of values, but no, it’s not how static type-checking is implemented. Some sets are very large (consider the set of all JSON values) and enumerating them isn’t useful.


Tho Typescript does have structural types, mapped types, union types, optional types, type aliases..... Bunch of useful type features.


More like indirectly influenced by Java by way of C# (Anders Hejlsberg designed both C# and TS)


I disagree. The language was probably more inspired by C#, which is itself inspired by Java. Type erasure is just part of transpiling to JS.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: