【发布时间】:2018-01-25 00:38:12
【问题描述】:
我有一个第 3 方模块(“handsontable”),它在模块文件夹(“/node_modules/handsontable/handsontable.d.ts”)中有过时的定义,但在 /node_modules/ 中有正确的“index.d.ts” @types 文件夹。 所以结构如下:
/node_modules
/@types
/handsontable
/index.d.ts (LATEST)
/handsontable
/handsontable.d.ts (OUTDATED)
/src/app.ts
我正在使用 es6 模块,我不想将 handsontable 暴露给全局,所以当我在 app.ts 中编写时:
import ht from 'handsontable'
let options: ht.Options
它显示错误,因为ht.Options 不存在于/node_modules/handsontable/handsontable.d.ts 中,而它仅存在于/node_modules/@types/handsontable/index.d.ts 中
是否有强制打字稿在import m from "module" 期间从/node_modules/@type/module 加载类型信息?
这是我的 tsconfig.json:
{
"exclude": [
"node_modules","build","dist", "typings","types"
],
"include": [
"./src/**/*.ts"
],
"typeAcquisition": {
"enable": true
// "exclude": [ //tried that too
// "handsontable"
// ]
},
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "node_modules",
"paths": {
"src/*":["../src/*"],
"app/*":["../src/*"],
"*":["../src/*", "./node_modules"]
},
"target": "es2016",
//"module": "es6", //es6 is not compatible with webpack.config.ts
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"allowJs": true,
"outDir": "./build",
"experimentalDecorators": true,
"lib": [
"dom",
"es6"
]
}
}
Typescript 版本:2.4.2
【问题讨论】:
-
你的
tsconfig文件中有什么? -
刚刚用信息更新了问题
-
首先您需要从排除的文件中删除类型。接下来你需要添加handsontable的类型,最后你需要排除problamatic类型。
-
你能提供一个小代码示例吗?我试过你说的没用,但我可能搞砸了路径相对论之类的
-
我尝试了所有组合,到目前为止我看到“node_modules/{module}/{module}.d.ts”总是优先于“node_modules/@types/{module}/index.d .ts" :-(
标签: typescript handsontable typescript-typings es6-modules