比方說,我有一個接口A
:如何在手稿中表達這一點?
interface A {
foo: number
bar: string
}
而且我有一個泛型類型Option
:
type Option<T> = {
map:() => T
}
然後我從A
和Option
創建一個新的接口B
:
interface B {
foo: Option<number>
bar: Option<string>
}
如何讓這個操作更一般? IE瀏覽器。我想這個API是:
type B = Lift<A>
凡Lift
到Option
的A
每個成員自動映射。請注意,A
可以有任意數量的任何類型的成員。
我該如何實現Lift
?如果這在TypeScript中不可行,是否有人有Scala/Haskell解決方案?
映射類型超級酷 - 感謝您的答案。 – bcherny