在我们转换为 Typescript 的过程中,我正在尝试为我们的 Javascript 文件添加类型。但是,我无法识别声明文件。
这是我的文件结构
- js
- Foo.js
- 打字
- 富
- 索引.d.ts
- 富
- 索引.ts
- 包.json
- tsconfig.json
Foo.js
module.exports = function Foo() {
return 'Bar';
};
索引.d.ts
export = Foo;
declare function Foo(): string;
索引.ts
import Foo = require('./js/Foo')
console.log(Foo());
tsconfig.json
{
"compilerOptions": {
"typeRoots": ["./typings"],
"target": "es5",
"strict": true,
"baseUrl": "./",
"paths": {
"*": ["typings/*"]
}
}
}
包.json
{
"name": "fail",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"tsc": "tsc"
},
"author": "",
"license": "MIT",
"dependencies": {
"typescript": "^3.1.4"
}
}
这是重现我的问题的回购
https://github.com/erisman20/typings_help
编辑:这是我得到的错误
error TS7016: Could not find a declaration file for module './js/Foo.js'. '....../js/Foo.js' implicitly has an 'any' type.