DEV Community

Discussion on: Using JSDoc to write better JavaScript Code

Collapse
 
oncode profile image
Manuel Sommerhalder

You get the type safety and autocompletion without using another language or changing the build pipeline with JSDocs. I really don't understand the hype for Typescript.

Collapse
 
peerreynders profile image
peerreynders

There is no type safety with plain JSDoc. It's

"An API documentation generator for JavaScript."

that some editors understand well enough to support code completion (which probably is the greatest factor of the "TypeScript in VS Code" popularity).

Preact's code base is written in JavaScript but it also provides TypeScript types in declaration files (e.g. internal.d.ts) which are then referenced in the JavaScript implementation files via JSDoc (e.g. create-element.js).

This means that the JavaScript doesn't have to be transpiled but can be type-checked (type-linted?) on demand with the TypeScript tooling.

The downside is that you have to be pretty good with TypeScript types to author the declaration files; meanwhile most developers aren't willing to leave the comfort of plain "TypeScript in VS Code" behind once they've grown accustomed to it.

Collapse
 
oowombatoo profile image
Vic Webster

Totally agree. TypeScript is okay. It's a tool, it has it's purposes. It's not an "improvement" or "fix" for JavaScript. Only people who have never bothered to learn JavaScript think like that.