1

我像这样安装了 Kepler.g:

npm i kepler.gl

它被添加到我的 package.json 中:

"kepler.gl": "^2.1.2"

但是,如果我尝试导入:

import keplerGlReducer from "kepler.gl/reducers";

我收到一个错误

Could not find a declaration file for module 'kepler.gl/reducers'. '/Users/grannyandsmith/web/web-admin/node_modules/kepler.gl/reducers.js' implicitly has an 'any' type.
  Try `npm install @types/kepler.gl` if it exists or add a new declaration (.d.ts) file containing `declare module 'kepler.gl/reducers';`ts(7016)

我也试过

npm install @types/kepler.gl

但正如预期的那样,它给了我npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fkepler.gl - Not found

我怎样才能解决这个问题?

编辑:

tsconfig 文件:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",
    "typeRoots": ["types/global.d.ts"]
  },
  "include": [
    "src"
  ]
}
4

1 回答 1

0

如果这些类型不适用于您要引入的特定库。这里有 2 个选项。

  • 自己添加类型(这可能会很痛苦,因为您必须了解完整的 API)。这样做的好处是所有类型都可用。

  • 另一种选择是创建一个声明文件*d.ts文件,让 TS 知道,嘿,我知道我在做什么。缺点是您没有可用的类型,并且自动完成功能不起作用。

@types/index.d.ts(需要让 TS 知道才能在此处找到类型)

declare module 'kepler.gl/reducers';
于 2020-04-21T18:44:57.150 回答