gpt4 book ai didi

javascript - 在 Typescript 类型声明中使用 Interface 来表达对象

转载 作者:行者123 更新时间:2023-12-03 02:09:45 25 4
gpt4 key购买 nike

我正在为一个框架编写类型声明,对于一个函数,它有一个类型为object的参数,但我想在中使用interface来描述它声明类型如下:

interface Options{
template: string | Selector | AST;
config (data: object): void;
}

interface Regular_Static {
new (options: Options): Regular_Instance;
// todo
}
declare var Regular: Regular_Static;

export = Regular

但是当我在我的应用程序中这样写时:

class HelloRegular extends Regular {
constructor(options: object){
super(options);
}
}

它表明类型对象不能分配给类型Options。那么如何处理呢?

补充:除非我们在应用程序中声明,否则无法在应用程序中获取Options类型声明。我的意思是让 Options 像对象一样工作。

最佳答案

此处采用正确的类型:

interface Options{
template: string | Selector | AST;
config (data: object): void;
}

class HelloRegular extends Regular {
constructor(options: Options){
super(options);
}
}

关于javascript - 在 Typescript 类型声明中使用 Interface 来表达对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49631248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com