3 ms·
Lately I've gotten into the habit of giving my pure JS projects a tsconfig.json file, so that my editor runs the files through tsc and I get all the code hints
by fenomas 5y ago
Lately I've gotten into the habit of giving my pure JS projects a tsconfig.json file, so that my editor runs the files through tsc and I get all the code hints and errors it reports.
I find that as long as the code is reasonably straightforward, I get most of TS's benefits without actually declaring any types. It was kind of a pain to originally set up, but the code hints really are pretty magical.
- derekbaker783 5y agoSame here (along with some JSDoc type annotations). This works well.
- fenomas 5y agoYes exactly - when tsc you really want code hints for an object, but tsc can't guess its type, you can do: /** @type {import('../index').Engine} */ this.engine = engine Most of my projects have a god object at the center, so if I explicitly type that one object then I get basically all the important code hints for free. A side benefit of this is that you can also use TypeDoc to generate docs. It's not really made for vanilla JS, but once I got over the initial road bumps I've been happy with the results.