我有一個函式,它的回傳型別為
。Promise<Record<
ReturnType。
Omit<SomeInterface, 'key1' | 'key2' >>
也就是說,之前我們知道key2總是被省略。
現在,該函式應該回傳相同的型別,但key2可能被省略,也可能不被省略。是否有一些方法可以做到這一點,比如說
Promise<Record<
ReturnType。
Omit<SomeInterface, 'key1' | 'key2'>> |
Record<
ReturnType,
Omit<SomeInterface, 'key1'> >>
uj5u.com熱心網友回復:
試一下:
type OptionalProperty<O, K extends keyof O> = Pick<Partial<O>, K> & Omit< O, K> 。
type T = Promise<Record<ReturnType, OptionalProperty< Omit<SomeInterface, 'key1'>, 'key2'>>。
uj5u.com熱心網友回復:
在Omit之后,你可以把它作為一個可選的屬性加回來。
比如說:
Promise<
Record<
ReturnType,
Omit<SomeInterface, 'key1' | 'key2'> & { key2? SomeInterface['key2'] }
>
>。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/324500.html
標籤:
