Abstract
I'm trying to import ".js" file from an external location (i.e. node_modules) I'm trying to do this using commonjs module pattern, however import wouldn't want to work with ".js" file types until I add ".d.ts" file near ".js" file in the same folder.
But the problem is that I wouldn't want to affect any node_modules with my ".d.ts" files. I want it to be located in another folder, separate from node_modules but as soon as I do that, typescript compiler throws an error:
Example
I have the following folder structure:
|- DTS
| |- y.d.ts
|- main.ts
|- y.js
y.js has the following content
module.export = function (x) {
console.log(x);
};
y.d.ts has the following content
export interface Y {
(x): any;
}
declare let y: Y;
export default y;
main.ts has the following content
import * as y from './y'
Now when I'm trying to compile main.ts with:
tsc -m commonjs -t ES2015 main.ts
I will get an error:
x.ts(1,20): error TS2307: Cannot find module './y'.
Question
How to import ".js" files and being able to define it's ".d.ts" declarations while having both files located in different locations.
Edit
Here is the link to example project. Be sure to use TypeScript version 2.0 compiler. And the tsc
command above to see the error.