【发布时间】:2018-08-01 17:09:51
【问题描述】:
首先,这是我的tsconfig.json:
{
"compilerOptions": {
"strict": true,
"importHelpers": false,
"inlineSources": true,
"noEmitOnError": true,
"pretty": true,
"module": "commonjs",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": false,
"removeComments": true,
"preserveConstEnums": false,
"sourceMap": true,
"lib": ["es2017","esnext.asynciterable"],
"skipLibCheck": true,
"outDir": "dist",
"target": "es2018",
"declaration": true,
"types" : ["node"],
"resolveJsonModule": true,
"esModuleInterop": false
},
"files": [
"src/DatabaseWrapper"
],
"exclude": [
"node_modules"
]
}
现在我尝试导入一个 JavaScript 库:
import Napi from '@org/napi-js';
我得到这个错误:
TS7016:找不到模块“napi-js”的声明文件。 '/home/mpen/Projects/my-project/node_modules/@org/napi-js/dist/index.js' 隐含了一个 'any' 类型。 尝试
npm install @types/org__napi-js(如果存在)或添加一个包含 `declare module 'org__napi-js' 的新声明 (.d.ts) 文件;
@types/org__napi-js 不存在,所以不好。那么如何正确申报呢?
我尝试创建一个文件,types/org__napi-js.d.ts',里面只有这个:
declare module 'org__napi-js';
然后我尝试更新我的tsconfig.json 以便它可以找到它:
{
"compilerOptions": {
...
"baseUrl": "./",
"paths": {
"*": ["types/*"]
}
},
...
但这没有任何帮助。
我该怎么办?或者,更明确地说:
- 如何告诉 TypeScript 在哪里可以找到我的模块?
- 在这个模块中最少需要多少代码才能说默认导出是
any?
我想我想将所有这些存根放在types/ 中,并将我的源代码放在src/ 中,除非有一些标准的方式来组织一个 TS 项目。
【问题讨论】:
标签: typescript