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

使用上述 [tsconfig.json],以下导入将被重写:
https://mintcdn.com/teemo/2s-4Z6VdGqiCeBNX/icons/typescript.svg?fit=max&auto=format&n=2s-4Z6VdGqiCeBNX&q=85&s=087b260066909db1cd3e9c7292bc34b2tsconfig.ts
import { z } from "my-custom-name"; // 从 "zod" 导入
import { Button } from "@components/Button"; // 从 "./src/components/Button" 导入

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