

|
noe132Mar 7, 2022
1
你这已经是最简洁的写法了
|
|
2
@noe132 可是继续加 SearchType 不就很难受了
|
|
anjianshiMar 7, 2022
3
确实是最简洁的写法了...
|
|
anjianshiMar 7, 2022
4
如果新加的 type 不需要 xSearchItems ,可以这样合并:
```typescript type Column = { xSearchType: 'input' | 'other' | 'other-other' } | { xSearchType: 'select', xSearchItems: any[] } ``` |
|
zhy0216Mar 7, 2022
5
应该可以用 conditional type
|
|
voidcommaMar 7, 2022
6
```typescript
type column<T> = T extends 'select' ? { xSearchType: T, xSearchItems: any[] } : { xSearchType: T } let c: column<'select'> = { xSearchType: 'select', xSearchItems: [], } let n: column<'input'> = { xSearchType: 'input', } ``` 暂时想到这样写,不过感觉还有更简洁的方法。 |
|
zhihaofansMar 7, 2022 via iPhone
7
没学过 ts 的好奇问一下,参数名前面都带个 x 是有什么用途
|
|
8
@zhy0216 看了下文档,没想出来怎么实现
|
|
9
@zhihaofans 我随手写的..,跟 ts 没关系
|
|
10
@xiaojie668329 要传泛型感觉也有点难受
|
|
zhy0216Mar 7, 2022
11
|