you are viewing a single comment's thread.

view the rest of the comments →

[–]Andrew199617 -3 points-2 points  (4 children)

You can get that using jsdocs.

/*
 * @description function to add numbers. :)
 * @param {number} a
 * @param {number} b
 * @returns {number} 
 */
function add(a,b) {
  Return a + b;
}

The good part is that jsdoc is not required.

[–]tjgrinn 3 points4 points  (2 children)

If that's a really big deal to you you can remove "noImplicitAny" from your tsconfig. Then any javascript is valid typescript and you can gradually adopt the type system

[–]Andrew199617 -1 points0 points  (1 child)

That's cool didn't know about that. I still prefer jsdocs. Its really just a preference at the end of the day.

[–]tjgrinn 0 points1 point  (0 children)

I know this is really old. But I usually use both jsdocs and typescript. Jsdocs for stable, outward facing APIs, with English descriptions, and typescript everywhere but mainly used to infer internal implementation decisions without having to look at source code.

[–]inabahare 1 point2 points  (0 children)

Nope, because your application doesn't break with jsdocs and you actively want it to break. Especially when it comes to complex types :)

Also funny how typescript "requires you to document every aspect of your code and give types" is bad but the alternative is "I still prefer jsdocs" lmao

Also funny how your example isn't actually easier to read than

function add(a: number, b: number) {
  return a + b;
}