I have existing project in nodejs + express in javascript. Currently everything is working on es5.
Now i added typescript in same project and i want to do all the new development in typescript. But i am facing a issue in accessing existing javascript files.
I found that i can create definition file xx.d.ts (not sure if it is correct approach) of each existing javascript file and then use it in typescript files.
For example i have javscript file
myFile.js
function myClass(){
//some functions here associated with this variable
}
exports.myData = new myClass();
now i want to use it in my new ts file
So what i did in ts file to access is
declare function require(path: string): any;
var auth = require('./myFile').myData;
I am not sure if this is the right approach. Secondly i tried with myFile.d.ts file as well.
I defined this file in following way
declare module './myFile' {
export var myData: any
}
But this gives error of relative path - TS2436 ambient module declaration cannot specify relative module path
Please let me know if anybody has any idea to resolve this problem or suggest if it is okay to go with first approach.
allowJSoption in your tsconfig.json? - unional