简体   繁体   中英

Typescript cannot find method in definition file

I have an existing Javascript file named app.min.js which comes with a website template. This file defines a function called pageSetUp that needs to be invoked when the DOM is loaded.

I have created a TypeScript definition file named app.d.ts which the following content:

interface App {
    pageSetUp();
}

It is referenced in the TypeScript file as follows:

/// <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'.

What am I missing?

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.

Try this instead in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM