【发布时间】:2021-12-08 03:49:05
【问题描述】:
假设我有一些泛型
type Foo<T = string, U = number> = {
t: T
u: U
}
T 和 U 都不是必需的。如何提供 U 而不是 T。
理想情况下我可以做类似的事情
type G = Foo<,string> // ???? expected syntax
// expected result ????
type G = {
t: string;
u: string;
}
我尝试过的事情:
type G = Foo<never, string> // ❌
type G = Foo<unknown, string> // ❌
type G = Foo<Foo['t'], string> // ❌ (Works in this exact example but not in the general case. I want to extract the first default parameter type rather than extracting out the resulting `t`).
【问题讨论】:
-
这能回答你的问题吗? Override only some of the generic variables
标签: typescript typescript-typings typescript-generics