# 内置 TypeScript

Deno 直接执行 `.ts` 与 `.tsx` 文件，类型检查器也随二进制分发。你不需要安装 `typescript`、`ts-node` 或 `tsx` 才能启动项目。

```bash
deno run main.ts       # 执行
deno check main.ts     # 静态类型检查
deno test --check      # 测试并检查测试模块图
```

<Callout type="warn" title="能运行不代表类型正确">
当前工作流应显式执行 `deno check`。不要把 `deno run` 成功当作完整类型验证，也不要等到生产启动时才发现类型问题。
</Callout>

## 配置原则

Deno-first 项目通常把少量 TypeScript 设置写在 `deno.json`：

```json
{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true
  }
}
```

既有 Node 项目的 `tsconfig.json` 可以继续被读取；如果同时存在带 `compilerOptions` 的 `deno.json`，后者优先。Deno 不负责输出 JavaScript，因此 emit 相关选项没有意义。

## Web、Worker 与 DOM 类型

默认类型环境面向 Deno runtime，不自动包含浏览器 `document`。共享浏览器代码时显式配置 `lib`，而不是用全局声明掩盖环境差异。

官方参考：[TypeScript support](https://docs.deno.com/runtime/fundamentals/typescript/)、[Configuring TypeScript](https://docs.deno.com/runtime/reference/ts_config_migration/)。
