I'm a selftaught (web) developer. On sunny days, you can find me hiking through the Teutoburg Forest, on rainy days coding or with a good fiction novel in hand.
VSCode also has this convenient builtin feature that allows you to infer types from those comments. You just have to activate this one:
"javascript.implicitProjectConfig.checkJs": true
I get why people prefer TS over JS Really. I just also noticed TS types clutter the code quite a bit (especially if you're used to dynamic typing) and require an additional compiling step. I seldom see this considered in posts about the two languages.
Yes, JSDoc is also a nice alternative if you don't want to use typescript .basically they both achieve the same things differently.
And One more compiling step does not affect anything at all because in the end, you are getting what you need.
The main thing is it boils down to personal preference that how you prefer writing your code.
jsdoc is way cumbersome to use, as compared to typescript (especially Typescript infering many things on its own, where as jsdoc is bit verbose).
Further more, Typescript provide compilation, and future javascript now.
I'm a selftaught (web) developer. On sunny days, you can find me hiking through the Teutoburg Forest, on rainy days coding or with a good fiction novel in hand.
I get your point. You've got to learn it, but so would you have to get used to Typescript syntax. I didn't really find it cumbersome. And about verbosity - that's what JSDoc is there for I guess. But instead of having all the types inside your code, you can keep them separate and even enrich them with intel that eventually ends up in your technical documentation. I'm sure there are ways around this as well, but then again why use TS next to JSDoc for automated doc creation?
I'm a selftaught (web) developer. On sunny days, you can find me hiking through the Teutoburg Forest, on rainy days coding or with a good fiction novel in hand.
Your comment got me curious on complex types - I haven't used JSDoc trying to declare such yet. Can you please explain this a bit further?
I couldn't find a lot of good examples in the ts docs, neither on the www.
Note that you can also use jsdoc for ts-like typing.
jsdoc.app/tags-typedef.html
VSCode also has this convenient builtin feature that allows you to infer types from those comments. You just have to activate this one:
I get why people prefer TS over JS Really. I just also noticed TS types clutter the code quite a bit (especially if you're used to dynamic typing) and require an additional compiling step. I seldom see this considered in posts about the two languages.
Yes, JSDoc is also a nice alternative if you don't want to use typescript .basically they both achieve the same things differently.
And One more compiling step does not affect anything at all because in the end, you are getting what you need.
The main thing is it boils down to personal preference that how you prefer writing your code.
jsdoc is way cumbersome to use, as compared to typescript (especially Typescript infering many things on its own, where as jsdoc is bit verbose).
Further more, Typescript provide compilation, and future javascript now.
I get your point. You've got to learn it, but so would you have to get used to Typescript syntax. I didn't really find it cumbersome. And about verbosity - that's what JSDoc is there for I guess. But instead of having all the types inside your code, you can keep them separate and even enrich them with intel that eventually ends up in your technical documentation. I'm sure there are ways around this as well, but then again why use TS next to JSDoc for automated doc creation?
TypeScript was built for application development, i Write and ship out products built with TypeScript faster than those built with JavaScript.
Yes, I do use JSDoc, along with
// @ts-check
, if I had to use JavaScript.However, not only that it is harder to declare complex types, but also that IntelliSense is still less smart, even with
ts-check
on.Your comment got me curious on complex types - I haven't used JSDoc trying to declare such yet. Can you please explain this a bit further?
I couldn't find a lot of good examples in the ts docs, neither on the www.
As far as I know, you can
/** @type {} */
to specify types for a variable/** @type {} */ (x)
to force a variable to type/** @typedef {} */
to declare a type in advanceBut still,
BTW, much of typing works inside
/** @type {} */
's bracelets. You can even useimport().Class
and use TypeScript interface syntax inside them.