【发布时间】:2020-02-25 13:07:17
【问题描述】:
这是我的 javascript 类:TestClass.js
/**
* http://usejsdoc.org/
*/
export class TestClass{
constructor(){
}
echo(){
alert("Echo")
}
}
这是我的定义文件:test.d.ts
/**
* http://usejsdoc.org/
*/
declare class TestClass{
public echo():void;
}
这是我的 ts 主文件:entry.ts
import * as go from "gojs";
import * as test from "./TestClass"
window.addEventListener( "load", delay );
function delay() {
var testClass=new test.TestClass()
TestClass.echo();
}
当我尝试使用 npm run build 构建它时
ERROR in /home/voffka/Documents/projects/typescript-tutorial/r-diagram1/r-diagram/src/entry.ts(9,15)
TS2339: Property 'echo' does not exist on type 'typeof TestClass'.
如何解决这个问题?
【问题讨论】:
-
您的意思是打电话给
testClass.echo()吗?否则,您将声明一个变量,然后从不使用它,并尝试静态调用该方法。 -
是的,我需要使用非静态方法
标签: javascript typescript type-definition