2017-08-16 47 views
0

我有第三方模塊(「handsontable」),它在模塊文件夾中有過時的定義(「 node_modules/handsontable/handsontable.d.ts「),但適當的」index.d.ts「位於/ node_modules/@ types文件夾中。 所以結構如下:「module/index.d.ts」和「@ types/module/index.d.ts」之間的Typescript衝突

/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

存在反正是有強制打字稿期間從/node_modules/@type/module加載類型信息3210?

這裏是我的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" 
     ] 
    } 
} 

打字稿版本:2.4.2

+0

你怎麼在你的'tsconfig'文件有哪些? – Nayish

+0

剛剛更新了信息的問題 –

+0

首先,您需要從排除的文件中刪除類型。接下來,您需要添加handontable的類型,最後您需要排除該類型的。 – Nayish

回答

0

正如評論"node_modules/{module}/{module}.d.ts"提到總是優先於"node_modules/@types/{module}/index.d.ts"

所以最好解決方法我可以找到迄今爲止映射tsconfig.json/compilationOptions /路徑

{ 
    compilationOptions:{ 
     baseUrl:"node_modules", 
     paths:{ 
     "handsontable":["@types/handsontable"] 
     } 
    }  
} 

什麼幫我找到它,是標誌TSC --traceResolutions