This website requires JavaScript.
Explore
Help
Register
Sign In
rou
/
front-end-example
Watch
1
Star
0
Fork
0
You've already forked front-end-example
Code
Issues
Pull Requests
Actions
Packages
Projects
Releases
Wiki
Activity
Files
3850ce7399061a80a78e98d428de896fb5fb2333
front-end-example
/
06-typescript
/
06-union-and-optional-props
History
rou
d5ff59ac76
update
2026-03-23 16:33:09 +08:00
..
answer.ts
feat: add TypeScript lessons and learning panel
2026-03-19 10:06:11 +08:00
README.md
feat: add TypeScript lessons and learning panel
2026-03-19 10:06:11 +08:00
starter.ts
update
2026-03-23 16:33:09 +08:00
README.md
Unescape
Escape
练习 6
:
联合类型和可选属性
目标
学会处理不固定的数据结构。
你要练什么
联合类型
可选属性
接口扩展场景
任务
定义一个带可选年龄的
User
接口
声明一个
id
,它可以是数字或字符串
分别创建有年龄和没有年龄的对象
文件
starter.ts
answer.ts