我这样安装了Kepler.g:
npm i kepler.gl
它被加到我的包裹里了。杰森:
"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"
]
}
2条答案
按热度按时间kpbwa7wx1#
如果类型不适用于您正在拉入的特定库。以下是两个选项。
*d.ts
,在这里你让TS知道,嘿,我知道我在做什么。缺点是你没有可用的类型,自动完成也不起作用。@types/index.d.ts(需要让TS知道在此处查找类型)
axzmvihb2#
我使用了Sushanth建议的类似方法。
并在我的
tsconfig.json
文件中添加了"typeRoots": ["src/types", "node_modules/@types"]
,以允许TS查找我的自定义声明