示例工程 23-esm-live-bindings

23-esm-live-bindings/05-export-star/README.md

markdown · 0.9 KB

运行:23 · export-star

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

# 05 · export-star
 
**演示**:`export *` 遇到同名导出会报 `TS2308`;显式选择后 barrel 可用。同一模块被多处导入只求值一次。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/23-esm-live-bindings/05-export-star/`;开 Console。
**预期控制台输出**:
```text
1:2:a
evaluations:1
a:1
b:1
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/23-esm-live-bindings/05-export-star/tsconfig.types.json`
**预期类型错误**(`demo/ambiguous.ts`,由 `tsconfig.fail.json` 触发):
```text
demo/ambiguous.ts(4,1): error TS2308: Module '../src/a.js' has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
```
**注意**:ESM 的「只求值一次」由模块图保证,不需要手写单例。