Skip to main content
Bun 会读取你 tsconfig.json 文件中的 paths 字段以重新写入导入路径。这对于别名包名或避免冗长的相对路径非常有用。
tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "my-custom-name": ["zod"],
      "@components/*": ["./src/components/*"]
    }
  }
}

根据上述 tsconfig.json,以下导入语句将被重写:
https://mintcdn.com/bun-zhcndoc/cnUTwgMuf4cCrwC-/icons/typescript.svg?fit=max&auto=format&n=cnUTwgMuf4cCrwC-&q=85&s=e7767043c9e885c34f2d6c8fe2a95217tsconfig.ts
import { z } from "my-custom-name"; // 从 "zod" 导入
import { Button } from "@components/Button"; // 从 "./src/components/Button" 导入

有关在 Bun 中使用 TypeScript 的更多信息,请参见文档 > 运行时 > TypeScript