TypeScript
zx is written in TypeScript and provides the corresponding libdefs out of box. Typings are TS 4+ compatible.
ts
// script.ts
import { $ } from 'zx'
const list = await $`ls -la`
Some runtimes like Bun or Deno have built-in TS support. Node.js requires additional setup. Configure your project according to the ES modules contract:
- Set
"type": "module"
in package.json - Set
"module": "ESNext"
in tsconfig.json.
Using TypeScript compiler is the most straightforward way.
bash
npm install typescript
tsc script.ts
node script.js
bash
npm install ts-node
ts-node script.ts
# or via node loader
node --loader ts-node/esm script.ts
bash
npm install swc-node
swc-node script.ts
bash
npm install tsx
tsx script.ts
bash
bun script.ts
bash
deno run --allow-read --allow-sys --allow-env --allow-run script.ts