示例工程 25-declaration-distribution

25-declaration-distribution/01-generate-dts/README.md

markdown · 0.9 KB

运行:25 · generate-dts

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

# 01 · generate-dts
 
**演示**:`declaration: true` + `emitDeclarationOnly: true` 只产出 `.d.ts` 与 `.d.ts.map`,不产出 JS。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/25-declaration-distribution/01-generate-dts/`;开 Console。
**预期控制台输出**:
```text
ADA
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/25-declaration-distribution/01-generate-dts/tsconfig.types.json`
**预期类型错误**(`demo/untyped-import.ts`,由 `tsconfig.fail.json` 触发):
```text
demo/untyped-import.ts(3,23): error TS7016: Could not find a declaration file for module '../../02-exports-matrix/fixtures/pkg/esm/index.js'. '.../esm/index.js' implicitly has an 'any' type.
```
**注意**:`tsconfig.build.json` 与 `tsconfig.json` 产出不同目录;测试读取 `dist/types/index.d.ts`。