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

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

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