示例工程 23-esm-live-bindings
23-esm-live-bindings/04-import-type/README.md
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
# 04 · import-type
**演示**:`import type` 只取类型,产物里完全擦除;值导入仍保留。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/23-esm-live-bindings/04-import-type/`;开 Console。
**预期控制台输出**:
```text
rect:6
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/23-esm-live-bindings/04-import-type/tsconfig.types.json`
**预期类型错误**(`demo/type-reexport.ts`,由 `tsconfig.fail.json` 触发):
```text
demo/type-reexport.ts(1,10): error TS1484: 'Shape' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
demo/type-reexport.ts(3,10): error TS1205: Re-exporting a type when 'verbatimModuleSyntax' is enabled requires using 'export type'.
```
**注意**:`verbatimModuleSyntax` 下,值导入与类型导入必须显式区分。