node.js - How to use existing javascript files in typescript files? -


i have existing project in nodejs + express in javascript. working on es5.

now added typescript in same project , want new development in typescript. facing issue in accessing existing javascript files.

i found can create definition file xx.d.ts (not sure if correct approach) of each existing javascript file , use in typescript files.

for example have javscript file

myfile.js

function myclass(){ //some functions here associated variable }  exports.mydata = new myclass(); 

now want use in new ts file

so did in ts file access is

declare function require(path: string): any;  var auth = require('./myfile').mydata; 

i not sure if right approach. secondly tried myfile.d.ts file well.

i defined file in following way

declare module './myfile' {   export var mydata: } 

but gives error of relative path - ts2436 ambient module declaration cannot specify relative module path

please let me know if has idea resolve problem or suggest if okay go first approach.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -