2017-08-16 11 views
0

Ich habe ein 3rd-Party-Modul ("handsontable"), das eine veraltete Definition im Modulordner hat ("/ node_modules/handsontable/handsontable.d.ts "), aber korrekt" index.d.ts "im Ordner/node_modules/@ types. So ist die Struktur ist die folgende:Typoskriptkonflikt zwischen "modul/index.d.ts" und "@ types/module/index.d.ts"

/node_modules 
    /@types 
    /handsontable 
     /index.d.ts (LATEST) 
    /handsontable 
    /handsontable.d.ts (OUTDATED) 
/src/app.ts 

I es6 Module verwende und ich will nicht handsontable globalen aussetzen, so dass, wenn ich in app.ts schreiben:

import ht from 'handsontable' 

let options: ht.Options 

Es zeigt me error, weil ht.Options nicht in /node_modules/handsontable/handsontable.d.ts existiert, während es existiert nur in /node_modules/@types/handsontable/index.d.ts

gibt es trotzdem Typoskript zu zwingen Typinformation von /node_modules/@type/module währendzu laden?

Hier ist meine 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" 
     ] 
    } 
} 

Typoskript Version: 2.4.2

+0

was machen Sie in Ihrer 'tsconfig' Datei haben? – Nayish

+0

gerade aktualisiert die Frage mit der Info –

+0

Zuerst müssen Sie Typen aus den ausgeschlossenen Dateien entfernen. Als nächstes müssen Sie die Art der Handschrift hinzufügen und schließlich müssen Sie die problamatic Typ ausschließen. – Nayish

Antwort

0

Wie im Kommentar erwähnt "node_modules/{module}/{module}.d.ts" immer Vorrang vor "node_modules/@types/{module}/index.d.ts"

So ist die beste Abhilfe könnte ich bisher finden, ist die tsconfig.json/compilationOptions/Pfade zuordnen:

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

Was mir geholfen, es zu finden, ist die Flagge tsc --traceResolutions