DEV Community

Discussion on: JS Functional Concepts: Pipe and Compose

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

Hahaha I prefer TS unless it's a quick script tbh, but IRL there are so many projects without TS that I feel like necessary to spread a bit of JSDoc (it makes it a lot easier to migrate JS to TS).

Type inference would be possible I guess but when you have functions that return different types then it will be a mess, I can imagine something like:

const userAge = getUserAge(); // inferred number
pipe( calcYearsBeforeRetirement, generateEmailBody, otherFunc )(userAge)
Enter fullscreen mode Exit fullscreen mode

userAge is a number, then you calc the amount of years he needs to work before he can retire, which can also be a number, everything OK here, then you cast this number as string inside the email body so the return type is not a number anymore but a string, and so on and so forth.

Hence I assume that even if TS tried, most of the time it could be wrong idk 😅

Some comments have been hidden by the post's author - find out more