示例工程 30-web-components-types

30-web-components-types/03-typed-events/README.md

markdown · 0.6 KB

运行:30 · typed-events

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

# 03 · typed-events
 
**演示**:自定义元素派发 `CustomEvent<ValueDetail>`;监听器里收窄后读取 `detail.value`。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/30-web-components-types/03-typed-events/`;开 Console。
**预期控制台输出**:
```text
value:7
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/30-web-components-types/03-typed-events/tsconfig.types.json`
**注意**:事件名是普通字符串,类型系统不会自动把 `'value-change'` 映射到 `ValueEvent`;需要在监听器里收窄。