TypeScript:引用resig';s延伸

TypeScript:引用resig';s延伸,typescript,Typescript,我试图引用使用Resig的“extend”的现有代码,但是我得到了一堆错误 ------test.ts-------- 错误: Supplied parameters do not match any signature of call target The name 'Class' does not exist in the current scope The property 'extend' does not exist on value of type '() => void' T

我试图引用使用Resig的“extend”的现有代码,但是我得到了一堆错误

------test.ts--------

错误:

Supplied parameters do not match any signature of call target
The name 'Class' does not exist in the current scope
The property 'extend' does not exist on value of type '() => void'
The name 'Class' does not exist in the current scope
我意识到最终我想将基于扩展的代码重写为TypeScript,但在此之前,我如何从新代码中引用它呢


我想这引出了一个更深层次的问题——为什么它会抱怨现有javascript代码中的类型错误?

TypeScript通常无法从外部javascript代码推断类型

您需要声明要调用的“扩展”代码的形状,以便TypeScript知道类型的形状:

declare class Class {
    static extend(body: any);
}

您可以直接将其放在源文件中(如果您只有一个文件项目),或者更准确地说,放在从源文件引用的“.d.ts”文件中。

我很困惑。如果我添加,您仍然会看到函数和变量之类的推断类型,因此有一些引用.js的用例不需要编写.d.ts file.right,但我的观点是,从您没有完全推断的东西中推断错误是没有用的。当前的行为意味着通常不可能引用现有的代码。
(copied from http://ejohn.org/blog/simple-javascript-inheritance/)
Supplied parameters do not match any signature of call target
The name 'Class' does not exist in the current scope
The property 'extend' does not exist on value of type '() => void'
The name 'Class' does not exist in the current scope
declare class Class {
    static extend(body: any);
}