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}
*/constgetLowerCase=s=>throwIfNotStr(s)||s.toLowerCase();
Compile time checks are always better than runtime checks. Interesting obsession. Given that argument would be typed, the only way it could fail is if you lied to the compiler at some point. Typically that might be the point of deserialization... Test your inputs in one place and then trust your compiler. Also, types show intent. JSDoc isn't a type checker (or is it?)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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....
Compile time checks are always better than runtime checks. Interesting obsession. Given that argument would be typed, the only way it could fail is if you lied to the compiler at some point. Typically that might be the point of deserialization... Test your inputs in one place and then trust your compiler. Also, types show intent. JSDoc isn't a type checker (or is it?)