Suppose there is a config.js file in which the constructor function is described:
function ConfigService () { this.greeting = function() {console.log('Hello World');} } What should a header file look like to import without errors?
Suppose there is a config.js file in which the constructor function is described:
function ConfigService () { this.greeting = function() {console.log('Hello World');} } What should a header file look like to import without errors?
Understood. This method is suitable for those who use nodeJS. In the .js file, you must specify
module.exports.ConfigService = ConfigService; In the .d.ts file, just export the function or class, if the constructor function is defined in the .js file:
expot class ConfigService { smt: {}; } or
export function ConfigService(): void; In your case, since this is a constructor function, you can describe a class.
Something like this:
declare module 'my-module' { export class ConfigService { constructor(); greeting(): void; } } See how and what you can create in the documentation .
Source: https://ru.stackoverflow.com/questions/931704/
All Articles
.jsfiles can be connected without.d.ts, only there will be no static typing. In your case, since this is a constructor function, you can describe a class. - Stepan Kasyanenko