DEV Community

Discussion on: No, TypeScript is not OOP version of JavaScript

Collapse
 
mikeborozdin profile image
Mike Borozdin

Is then functional programming harder in TS than in JS? Yes it is slightly

Why is it harder? You can still pass functions as arguments, return them from the other functions, and use popular algorithms like map() and filter(). And type safety helps you avoid making mistakes.

This last one is outside of the original argument, but if not OOP, then natural choice is Functional >programming, so if we resign from classes we will most probably write functions and data >transformations in the functional style.

Why is it a natural choice? Are we confusing here procedural programming and functional programming?

Collapse
 
macsikora profile image
Pragmatic Maciej

Thank you for your comment.

FP is harder, try to do typing for pipe, compose or curry. Trivial in JS hard in TS. Or try to represent polimorhic FP abstractions like functors. You can do it but you need to create typing for every Functor instance, you cannot easily do it without some HKT hacks available there. If you don't believe me check how look Ramda types declarations.

Yes you can fallback to unsound type like any but then we get type wholes and less compiler help.

For the second, I don't think anybody today is considering using procedures (void functions), and not use a bit of functional or oop abstractions in the code. So no I didn't confuse anything.

Collapse
 
jopie64 profile image
Johan

With TypeScript 4 they alleviated the pain involved in typing e.g. ramda pipe a bit! They introduced variadic tuple types 🎉