Hacker News new | ask | show | jobs
by fenomas 1037 days ago
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.

1 comments

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!