示例工程 15-type-testing-api-design
15-type-testing-api-design/01-type-assertions/README.md
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
# 01 · type-assertions
**演示**:用 `Equal`/`Expect` 做类型级正例,用带原因的 `@ts-expect-error` 做负例。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/15-type-testing-api-design/01-type-assertions/`;开 Console。
**预期控制台输出**:
```text
3
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/15-type-testing-api-design/01-type-assertions/tsconfig.types.json`
**预期类型错误**(`demo/unused-expect.ts`,由 `tsconfig.fail.json` 触发):
```text
demo/unused-expect.ts(5,1): error TS2578: Unused '@ts-expect-error' directive.
```
**注意**:负例的 `@ts-expect-error` 必须紧跟会报错的那一行;注释里要写原因。