Hacker News new | ask | show | jobs
by timmg 1399 days ago
Oh, maybe that's exactly what I want.

This is just for personal projects. But I sometimes write JS code for the browser and I tend to not want to use any 3rd party libraries. But I do like the extra type checking. So I just want something that does the type checking and does TS to JS -- but without installing npm (which I have some irrational dislike for -- maybe just because I don't understand it enough).

3 comments

One other alternative to npm that is very useful for this specific case is npx. `npx typescript` will download typescript, cache it somewhere outside of the current project (often %LocalAppData% on Windows or near equivalent elsewhere), and then run it. You can run specific versions with `npx typescript@4`. You can follow that with command line arguments for typescript.

npx is installed right alongside npm in Node installs for some time now.

Learning npm is still often a good idea when working with Node. One thing that may be useful to learn here: npm has a concept of a development dependency needed only for development, not run time. You can install one with `npm install --save-dev typescript` for example. (Or `npm i -D typescript` if you want to save some typing.)

You can clean out dev dependencies with `npm prune --production`. Or if you are in a fresh install situation (a fresh git clone, for instance) and you want to skip developer dependencies you can `npm install --omit=dev`.

I find the distinction between production dependencies and developer dependencies quite useful.

Yeah, this is the answer. TBH..... you should get over your fear of npm. If you already have node installed you can just run npm i -g typescript ts-node

This will give you tsc as a global command line to compile typescript to javascript.

ts-node is optional, but it is the standard node cli that can run typescript

After you install these two you can just ignore that you have npm forever.

(... but yes you can also just download the js file as the person above suggested if you're really stuck on being anti-npm)

If you don't like npm, try yarn or pnpm. Both are excellent alternatives.