V
V
Vladimir Mirka2019-01-13 20:04:00
JavaScript
Vladimir Mirka, 2019-01-13 20:04:00

How to import a js file into a TypeScript project?

Let's say we have a config.js file that defines a constructor function:

function ConfigService () {
    this.greeting = function() {console.log('Hello World');}
}

What should the header file look like in order to import without errors?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2019-01-13
@search

Describe the library interface in a .d.ts file. Name this file something like global.d.ts and put it in the root of the project (where all the ts files are, usually the /src folder). You can read more here https://basarat.gitbooks.io/typescript/docs/types/... . Here is the complete documentation https://www.typescriptlang.org/docs/handbook/decla... .
The file itself will look something like this:

// global.d.ts
declare function ConfigService();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question