请教下,这里如何让 AccountResult2 继承 Account 的属性,同时 AccountResult2 还可以是 undefined?
已解决
悬赏分:20
- 解决时间 2022-01-05 05:38
点赞 0反对 0举报 0
收藏 0
分享 0
回答2
最佳
-
你想要的是不是这种效果?
// 合法 const t1: Account2 = undefined // 合法 const t2: Account2 = { username: 'sdf', password: 2 } // 合法 const t3: Account2 = { username: 'sdf', password: 2, hello: 'sdf' } // 非法 const t4: Account2 = { hello: 'sdf' } // 非法 const t5: Account2 = { username: 'sdf', hello: 'sdf' }
那可以这么写:
type Account2 = undefined | (Account & { [key: string]: any })
支持 0 反对 0 举报2022-01-04 08:33