I am trying add typings for our Javascript files at work while we are in the process of converting to Typescript. However, I can not get the declaration files to be recognized.
Here 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"
}
}
Here is repo to reproduce my problem
https://github.com/erisman20/typings_help
Edit: Here is there error I get
error TS7016: Could not find a declaration file for module './js/Foo.js'. '....../js/Foo.js' implicitly has an 'any' type.
"js/*": ["js/*"]
to the paths and reference the js file usingimport Foo = require('js/Foo')
? Then the rootDirs no longer works – Berna