DEV Community

loading...

Discussion on: Cool stuff with Typescript

Collapse
functional_js profile image
Functional Javascript • Edited

Excellent refresher on some Typescript features Amine.

I don't use .ts files, but I get near all the services of TS with JSDocs, while allowing the code to remain pure JavaScript.

TS also willl not give runtime checks, as it downpiles to untyped JS.

To use your lowercase example above, to enforce runtime checks (where the productions bugs are found), I use this idiom....

/**
@func
lowercase all chars in a str

@usages
in pipes
- instead of method chaining

@param {string} s
@return {string}
*/
const getLowerCase = s => throwIfNotStr(s) || s.toLowerCase();
Forem Open with the Forem app