Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 后续变量声明必须具有相同的类型-在哪里可以找到原始声明_Typescript - Fatal编程技术网

Typescript 后续变量声明必须具有相同的类型-在哪里可以找到原始声明

Typescript 后续变量声明必须具有相同的类型-在哪里可以找到原始声明,typescript,Typescript,我声明了一个接口ElementStatic和一个实现它的变量: interface ElementStatic { new(s: string, s2: any): Element; } declare var Element: ElementStatic 但编译器抱怨: 后续变量声明必须具有相同的类型。变量“Element”的类型必须为“{new():Element;prototype:Element}”,但此处的类型为“ElementStatic” 这对我来说意味着:在我的代码

我声明了一个接口
ElementStatic
和一个实现它的变量:

interface ElementStatic {

    new(s: string, s2: any): Element;
}

declare var Element: ElementStatic
但编译器抱怨:
后续变量声明必须具有相同的类型。变量“Element”的类型必须为“{new():Element;prototype:Element}”,但此处的类型为“ElementStatic”


这对我来说意味着:在我的代码中的某个地方,必须有一个具有给定类型的
Element
声明。但是没有,至少我找不到。我能做什么?

元素的声明不在代码中,而是在Typescript的默认库中


我是通过在Visual Studio中按F12找到的,弹出的代码将列出所有声明位置。

元素的声明不在代码中,而是在Typescript的默认库中


我是通过在Visual Studio代码中按
F12
找到这一点的。弹出窗口将列出所有声明位置。

我可以扩展元素的定义吗?在我的Visual Studio代码实例中,
F12
弹出窗口只会显示“未找到元素的定义”。:(@Ferenjito如果光标位于变量名
元素
内,则应将光标指向definitions@Ferenjito我看不到向
Element
添加额外构造函数的方法。您可以将其别名为
var moonement:{new(n:string,attr:any):Element}=Element as any;
我将提出一个新问题,问题更为具体。我可以扩展Element的定义吗?在我的Visual Studio代码实例中,
F12
弹出窗口简单地说“找不到Element的定义”。:(@Ferenjito如果光标位于变量名
元素
内,则应将光标指向definitions@Ferenjito我看不到向
Element
添加额外构造函数的方法。您可以将其别名为
var moonement:{new(n:string,attr:any):Element}=元素;
我会问一个新问题,问题会更具体一些