Hacker News new | ask | show | jobs
by franky47 1042 days ago
Sorry for being that guy, but this should probably be called "typechecking without transpilation".

What ends up being written is not TypeScript syntax (which does require transpilation to run).

JSDoc is awesome for incremental adoption though, I've migrated a few codebases this way without too much pain.

2 comments

Not TypeScript the language, but TypeScript the typechecker program. “Typescript without transpilation” is still perfectly accurate.
Vouched. This is the point of the thing - the typechecking benefits come from running `tsc` on your code (or VSCode will do it for you in the background and show you linter errors if you have typescript installed somewhere it knows about).

Incidentally I've been doing my JS projects this way for 2-3 years and I really dig it.

I started one side project like this recently and it's been great so far.
There's a few clunky bits but I hardly ever run into them.

Actually since this conversation is going, here's something I just learned this week that somebody might find helpful. I used to consider enums one of the clunky bits, but I just ran across the `keyof` operator:

    var modeNames = { FOO: 1, BAR: 2 }

    /** @param {keyof modeNames} mode */
    export function doThing(mode) {
        // the jsdoc type above is equivalent to {'FOO'|'BAR'}
    }
Probably old hat to TS people, but since I came at it from the other direction (I'd been using JSDoc for traditional doc-creation reasons before I realized VSCode could use it for linting and type hints) it was news to me.
That is indeed a neat trick!
That's my one grief with tsc: it does too many different things.

- Type checking

- Transpiling to multiple formats (CJS/ESM, JSX and the like)

- Generating declaration files (.d.ts)

While there are modern alternatives for transpiling, much faster than tsc (esbuild, swc), typechecking and declaration generation are still very slow operations.

Is there some command you can run to rewrite all the JSDoc as actual TypeScript?
Programmatically yes: https://github.com/microsoft/TypeScript/blob/28cd1fbd13b8d09...

You just need to call this from somewhere like ts-morph.