4 ms·
This might sound odd, but: one thing I've wanted to do is use the Typescript compiler without using NPM. (I'm not smart enough to know why I hate NPM. I just
by timmg 4y ago
This might sound odd, but: one thing I've wanted to do is use the Typescript compiler without using NPM. (I'm not smart enough to know why I hate NPM. I just want a tool that compiles TS.)
It almost sounds like I could write a self-contained deno command-line "app" that does this. Does that seem right (for those that know better)?
- ricardobeat 4y agoWhat you're looking for is ESBuild: https://esbuild.github.io/ https://esbuild.github.io/ TS "compilers" basically strip out the type annotations, they don't care about the validity of the types, so you'll be missing out on the main reason to be using TypeScript.
- tomxor 4y agoesbuild is so awesome... my steps towards web dev sanity are 1. Switch everything to esbuild, remove 10k dependency security nightmare, bloatfest and slugishness of pretty much every other node based build system / bundler. 2. Switch to deno. Haven't quite got to deno yet, but #1 was liberating. esbuild also has some preliminary deno support, but not sure how stable it is. The main thing I like about esbuild is that I feel like I wont ever have to "migrate" build system again (and I have to deal with an unusually high number of repos so this is a big deal), not much in my repos have anything esbuild specific, migrating was more a matter of removing build system specific smells from repos, it's all just a js and css bundle now. i.e there could be something better than esbuild in the future, and switching to that should in theory be effortless. This has never been true for all of the NPM build systems prior, (I was there at the beginning with grunt).
- vbezhenar 4y agoWhy do you want to switch to deno? I still don't understand what's the reason to use it over node.
- conaclos 4y agoTypeScript support?
- norman784 4y agoNot OP, but in paper deno offers a lot of things out of the box > - Provides web platform functionality and adopts web platform standards. > - Supports TypeScript out of the box. > - Has built-in development tooling like a dependency inspector (deno info) and a code formatter (deno fmt). Also they have a build-in testing library, so for me is mostly get rid of the tooling as dependency, the only thing that is missing is a frontend bundler (I think they have one, but intended to use for the backend only), but there are swc and rebuild that hopefully will catch the feature parity with webpack and friends.
- timmg 4y ago> TS "compilers" basically strip out the type annotations, they don't care about the validity of the types, so you'll be missing out on the main reason to be using TypeScript. I guess I'd want a Typescript compiler that does the "type checking" before stripping out the type annotations. Like that's how TS is supposed to work. If ESBuild doesn't do the type checking, then it probably doesn't fit my need. Edit: In fairness, if my IDE does the type-checking, this is almost good enough.
- lukevp 4y agoYou can run esbuild during development for quick builds and eslint for ide typescript enforcement, and then use tsc plus eslint during a production build to enforce type checking.
- diroussel 4y agoOne option is to do type checking with tsc (or in your unit tests). And build into a single file with tsup. https://tsup.egoist.dev/ https://tsup.egoist.dev/
- nextaccountic 4y agoOr swc https://swc.rs/ https://swc.rs/
- wwwigham 4y agoErrr, why do you need any non-js-runtime tool for this? TS's normal `tsc` command line is a single js file - you can pull it straight from GitHub[1] or unpkg[2] and run it directly in node without installing a full package via a package manager if you'd for some reason like to. [1] https://raw.githubusercontent.com/microsoft/TypeScript/main/lib/tsc.js https://raw.githubusercontent.com/microsoft/TypeScript/main/... [2] https://unpkg.com/typescript@4.7.4/lib/tsc.js https://unpkg.com/typescript@4.7.4/lib/tsc.js
- timmg 4y agoOh, 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).
- itslennysfault 4y agoYeah, 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)
- latchkey 4y agoIf you don't like npm, try yarn or pnpm. Both are excellent alternatives.
- WorldMaker 4y agoOne 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.
- beaker52 4y ago`ts-node` is my go-to. You could even `npm install -g` it.