It’s unobtrusive because you can use it anywhere regardless of JS runtime. It may not be as ergonomic or feature rich compared to using actual typescript but sometimes you just have to work with you have- like when you’re working on a codebase that is purely vanilla JavaScript.
I’m not advocating skipping typescript because you can do some of what it does with jsdoc, rather I’m saying if you’re forced to work in plain JavaScript there’s no reason not to use it. Writing jsdoc annotations brings in nice editor features (for those that support it) and that’s not even going into the documentation gains for a large codebase. There’s really nothing to loose by opting to use it. The time spent writing it is time saved later as a result of having decent, in some cases comprehensive, type annotations to help document your code.
I say that from experience- I spend time annotating type information that is as comprehensive as I can manage to get it when I write vanilla JS code. While writing a bunch of @imports to bring in @typedefs may be annoying, the benefit over time outweighs just winging it from memory.
IMO it is better to lean on Typescript than JSDoc even in this situation. Typescript has always been a superset of JS, and part of its contract is that JS behaviour cannot change based on type annotations. The compiler only determines valid/invalid programs.
As a result, you can add TS to an existing JavaScript database and only add type annotations where you want: do it incrementally or just leave half your codebase untyped if that’s what you want.
Most projects already have a build phase of some sort, but with TS it can be as simple as just removing the type annotations and the JS that remains has exactly the same behaviour.
3
u/[deleted] Mar 30 '22
It’s unobtrusive because you can use it anywhere regardless of JS runtime. It may not be as ergonomic or feature rich compared to using actual typescript but sometimes you just have to work with you have- like when you’re working on a codebase that is purely vanilla JavaScript.
I’m not advocating skipping typescript because you can do some of what it does with jsdoc, rather I’m saying if you’re forced to work in plain JavaScript there’s no reason not to use it. Writing jsdoc annotations brings in nice editor features (for those that support it) and that’s not even going into the documentation gains for a large codebase. There’s really nothing to loose by opting to use it. The time spent writing it is time saved later as a result of having decent, in some cases comprehensive, type annotations to help document your code.
I say that from experience- I spend time annotating type information that is as comprehensive as I can manage to get it when I write vanilla JS code. While writing a bunch of @imports to bring in @typedefs may be annoying, the benefit over time outweighs just winging it from memory.