示例工程 17-pre-module-globals

17-pre-module-globals/01-global-collision/README.md

markdown · 0.8 KB

运行:17 · global-collision

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

# 01 · global-collision
 
**演示**:三个 classic 脚本都写同一个全局 `config`,最后加载的那个生效,前两个被静默覆盖。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/17-pre-module-globals/01-global-collision/`;开 Console。
**预期控制台输出**:
```text
blue
true
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/17-pre-module-globals/01-global-collision/tsconfig.types.json`
**预期类型错误**(`demo/missing.ts`,由 `tsconfig.fail.json` 触发):
```text
demo/missing.ts(3,22): error TS2304: Cannot find name 'missingGlobal'.
```
**注意**:`types/globals.d.ts` 只是声明形状,运行时是否冲突由脚本加载顺序决定。