網站搜尋

自訂類型與匯入在 TypeScript 中無法使用


所以我正在為我的應用程式編寫自己的 typings 文件。我在根目錄有一個 @types 資料夾。一切運作良好:我已經更新了 tsconfig,讓 webpack 和我的 IDE 知道去哪裡找到 typings。

我在介面中定義的其中一個變數應該來自外部庫的某種類型。但當我將特定類型導入到 typings 文件時,typings 文件就被損壞了或出現了其他問題,因為在我的應用程式中再也找不到任何已定義的介面了!

import {GraphQLError} from '../../node_modules/@types/graphql/error/GraphQLError';

interface IResponse{
  data?: {
    views: Array<IViewScheme>
  };
  errors?: Array<GraphQLError>;
  loading: boolean;
}

我也嘗試過不同的路徑,比如 @types/graphql 等等。但全部都一直失敗。當我移除這個導入時,一切都正常...

我在這裡做錯了什麼?

編輯:

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noEmit": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "strictNullChecks": false,
    "lib": [
      "dom",
      "es6"
    ],
    "typeRoots": [
      "node_modules/@types",
      "@types"
    ],
    "types": [
      "graphql",
      "hammerjs",
      "jasmine",
      "node",
      "source-map",
      "uglify-js",
      "webpack",
      "vizceral"
    ]
  },
  "exclude": [
    "node_modules",
    "dist"
  ],
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}