You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
545 B
21 lines
545 B
type Props = { a: number; b: string; c: boolean }
|
|
|
|
// 查看 Props 中 a 的类型
|
|
type TypeA = Props['a']
|
|
|
|
// 模拟 Partial 类型:
|
|
type MyPartial<T> = {
|
|
[P in keyof T]?: T[P] // p 相当于 key
|
|
}
|
|
|
|
type PartialProps = MyPartial<Props>
|
|
|
|
|
|
// 索引其它查询方式:同时查询多个索引的类型
|
|
type TypeB = Props['a' | 'b']
|
|
|
|
type Props2 = { a: number; b: number; c: boolean }
|
|
|
|
type TypeC = Props2['a' | 'b']
|
|
// a 和 b 类型都是 number,TypeD 只显示一个 number,实现去重功能
|
|
type TypeD = Props2[keyof Props]
|