Skip to content

TypeScript

zx 用 TypeScript 编写,并提供开箱即用的相应 libdef。类型兼容 TS 4+。

¥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`

某些运行时(例如 BunDeno)具有内置 TS 支持。Node.js 需要额外的设置。根据 ES 模块合同 配置你的项目:

¥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:

使用 TypeScript 编译器是最直接的方法。

¥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

google/zx 中文网 - 粤ICP备13048890号