示例工程 13-declaration-files
13-declaration-files/02-global-augmentation/README.md
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
# 02 · global-augmentation
**演示**:`declare global { interface Window { appVersion: string } }` 给全局 `Window` 补字段。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/13-declaration-files/02-global-augmentation/`;开 Console。
**预期控制台输出**:
```text
1.0.0
1.0.0
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/13-declaration-files/02-global-augmentation/tsconfig.types.json`
**预期类型错误**(`demo/not-module.ts`,由 `tsconfig.fail.json` 触发;该配置刻意把 `moduleDetection` 设为 `legacy`):
```text
demo/not-module.ts(3,9): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
```
**注意**:`declare global` 必须写在模块内(文件里有 `export`),否则报 `TS2669`。