【发布时间】:2020-09-06 08:18:41
【问题描述】:
我正在尝试为 quadstore 库编写声明文件。该库定义了一个接受构造函数参数contextKey 的类。此参数的值确定方法参数上的字段名称。简化后,等效的 Typescript 将是:
interface MethodArg {
a: string;
b: string;
<<Whatever is supplied as the value of contextKey or a default name>>: string;
}
class A {
constructor(options?: {contextKey: string}) {}
fn(arg: MethodArg) {...}
}
我如何声明MethodArg 的类型以表示第三个属性名称取决于赋予类构造函数的值(在声明文件中)?这可能吗?
【问题讨论】:
-
泛型,可能
标签: typescript