0
我在foo/bar.js
内部有一个带有Node JS模块的项目。现在我正在编写一个TypeScript模块src/mymod.ts
,它应该导入foo/bar.js
。如何为foo/bar.js
模块编写声明文件?声明文件应该放在哪里?嵌套模块的声明文件
我试着放置一个声明文件中foo/bar.d.ts
但是当我import * as bar from "../foo/bar"
在我的打字稿模块,我得到以下错误:
File '/tmp/my_proj/foo/bar.d.ts' is not a module.
这是我tsconfig.json
文件
{
"compilerOptions": {
"allowJs": true,
"outDir": "./dist/",
"target": "es2017",
"module": "commonjs",
"strictNullChecks": true
},
"include": [
"./src/"
]
}
这是我的申报文件:
// Type definitions for bar
declare module "bar" {
function fun1(n: number) : number;
function fun2(n: number) : number;
function fun3(n: number) : number;
}
在我看来,'bar.d.ts'没有正确声明,如果你没有任何'export'语句,它不是一个能够解释错误的模块 - 如果你可以包含在你的问题中,我可能会帮助更多的文件。 – Gerrit0
@ Gerrit0忘了添加声明文件。现在补充,谢谢 –
@ Gerrit0所以,我已经设法解决这个问题,通过删除'module'构造并添加'export'到函数(实际上我有几个函数)。我认为模块是自动导出的? –