[英]Typescript cannot find method in definition file
I have an existing Javascript file named app.min.js which comes with a website template. 我有一个名为app.min.js的现有Javascript文件,该文件带有网站模板。 This file defines a function called pageSetUp that needs to be invoked when the DOM is loaded.
该文件定义了一个名为pageSetUp的函数,在加载DOM时需要调用该函数。
I have created a TypeScript definition file named app.d.ts which the following content: 我创建了一个名为app.d.ts的TypeScript定义文件,其内容如下:
interface App {
pageSetUp();
}
It is referenced in the TypeScript file as follows: 在TypeScript文件中按如下方式引用它:
/// <reference path="../typings/app.d.ts"/>
However, when add the following line to the constructor of this class like this: 但是,将以下行添加到此类的构造函数中时:
module ViewModel {
export class TableViewModel {
constructor() {
pageSetUp();
}
}
}
The build fails with error: "Could not find symbol 'pageSetUp'. 构建失败,并显示错误:“找不到符号'pageSetUp'。
What am I missing? 我想念什么?
TIA. TIA。
app.d.ts
is defining a method on an interface called App
, but the TableViewModel
is trying to use a global function called pageSetUp
, which is not defined. app.d.ts
正在定义一个名为App
的接口上的方法,但是TableViewModel
试图使用一个名为pageSetUp
的全局函数,该函数未定义。
Try this instead in app.d.ts
: 在
app.d.ts
尝试以下app.d.ts
:
declare function pageSetUp();
This declares a global function, but doesn't implement it, so no associated JavaScript is generated, but the function definition can be referenced from other TypeScript files. 这声明了一个全局函数,但未实现它,因此不会生成关联的JavaScript,但是可以从其他TypeScript文件中引用该函数定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.