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
Post a Comment