As part of our transition to Typescript at work, I've been working on adding typings to our Javascript files. However, I'm facing an issue with getting the declaration files recognized.
Below is my file structure:
- js
- Foo.js
- typings
- Foo
- index.d.ts
- Foo
- index.ts
- package.json
- tsconfig.json
Foo.js
module.exports = function Foo() {
return 'Bar';
};
index.d.ts
export = Foo;
declare function Foo(): string;
index.ts
import Foo = require('./js/Foo')
console.log(Foo());
tsconfig.json
{
"compilerOptions": {
"typeRoots": ["./typings"],
"target": "es5",
"strict": true,
"baseUrl": "./",
"paths": {
"*": ["typings/*"]
}
}
}
package.json
{
"name": "fail",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"tsc": "tsc"
},
"author": "",
"license": "MIT",
"dependencies": {
"typescript": "^3.1.4"
}
}
To see the problem in action, check out the repository here.
Edit: Below is the error message I receive:
error TS7016: Could not find a declaration file for module './js/Foo.js'. '....../js/Foo.js' implicitly has an 'any' type.