【发布时间】:2020-07-22 07:44:02
【问题描述】:
例如
interface IWithManyGenericTypes<First, Second, Third, Fourth> {
prop1?: First,
prop2?: Second,
prop3?: Third,
prop4?: Fourth
}
我想为特定的泛型类型设置类型,例如number,例如:
const someObject: IWithManyGenericTypes<Third = number> = {
prop3: 123
}
有没有办法做类似的事情?
【问题讨论】:
-
尝试:
<Third extends number>而不是<Third = number> -
Stutje,它不起作用,我试过了,这就是 vscode 所说的:
Generic type 'IWithManyGenericTypes<First, Second, Third, Fourth>' requires 4 type argument(s). -
Check out this sandbox,这有帮助吗?
-
不,它没有。也许this sandbox 会比我解释得更好。
标签: typescript generics typescript-generics