示例工程 15-type-testing-api-design

15-type-testing-api-design/02-utility-type-tests/README.md

markdown · 0.6 KB

运行:15 · utility-type-tests

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

# 02 · utility-type-tests
 
**演示**:为 `Partial<Pick<...>>`、`Readonly<Pick<...>>` 写精确类型断言,防止工具类型行为漂移。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/15-type-testing-api-design/02-utility-type-tests/`;开 Console。
**预期控制台输出**:
```text
1:Ada:ada@example.com
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/15-type-testing-api-design/02-utility-type-tests/tsconfig.types.json`
**注意**:类型测试断言的是「形状」,运行时仍是普通对象浅合并。