1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the clarification. Will read more on this. It sounds like a TypeScript interface is defined only for corresponding javascript "namespaces".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.