DEV Community

Discussion on: Static Typing or Typescript

Collapse
 
jessekphillips profile image
Jesse Phillips

I haven't used Typescript enough, I can't even articulate what is wrong with Typescript, and it has nothing to due with it not being sound.

At one point I was converting a type to any then to the type I wanted and I haven't dived in to what was wrong with my understanding.

Collapse
 
kayis profile image
K

To me, it's mostly that TS makes JS look like C# and I was quite happy with how JS looked like before.

TS codebases are too OOP heavy for my taste.

Thread Thread
 
jessekphillips profile image
Jesse Phillips

I could see how the introduction of typing would feel more like C# OOP than Javascript OOP. But make no mistake, Javascript is very much OOP and Typescript is not like C#.

Thread Thread
 
kayis profile image
K

Could be.

But I really think JS OOP is the right way and chipping away from it goes in the wrong direction.

Thread Thread
 
peerreynders profile image
peerreynders • Edited

Javascript is very much OOP and Typescript is not like C#.

From the horses mouth: TypeScript began its life as an attempt to bring traditional object-oriented types to JavaScript so that the programmers at Microsoft could bring traditional object-oriented programs to the web.

Java and C# implement (traditional) "class-based object-orientation" - class membership is static for the lifetime of the class instance (object). In JavaScript classes are a mere "template for creating objects", i.e. during its lifetime an individual object's spec can be changed to align with completely different classes without changing its identity.

JavaScript's "prototype-based dynamic object-oriented programming" is based on Self. I tend to think of JavaScript as Function-Oriented (Yes, JavaScript is a Lisp).

Collapse
 
peerreynders profile image
peerreynders

In situations where a function is dealing with a parametric type (generics) but it isn't interacting with the actual type value it's sometimes useful to use unknown as a type value.

Furthermore you typically narrow types with type assertions, user-defined type guards or assertion functions.