尝试从 aws-appsync lib 修复“找不到模块的声明文件”会导致另一个错误

Ped*_*tes 6 typescript reactjs typescript-typings

我正在使用aws-appsync库,但出现此错误:

(4,42): 找不到模块“@redux-offline/redux-offline/lib/types”的声明文件。'node_modules/aws-appsync/node_modules/@redux-offline/redux-offline/lib/types.js' 隐式具有 'any' 类型。尝试npm install @types/redux-offline__redux-offline它是否存在或添加一个新的声明 (.d.ts) 文件,其中包含declare module '@redux-offline/redux-offline/lib/types';

然后我添加declare module @redux-offline/redux-offline/lib/types;到我的typings.d.ts以检查该错误是否消失,但我得到了其他:

/node_modules/aws-appsync/lib/store.d.ts (13,69):不能使用命名空间“NetworkCallback”作为类型。

现在我不知道如何修复最后一个错误,因为我没有在互联网上找到很多关于它的信息。

我不知道这是否重要,但它packages/web/node_modules/@redux-offline/redux-offline/lib/types.js是一个只有"use strict";行的文件。

一个有效的解决方案是 setting noImplicitAny: false,但我已经阅读过它并且它不是一个好的解决方案。

谢谢!

Ped*_*tes 8

所以我打开文件/node_modules/aws-appsync/lib/store.d.ts,有两种类型导入@redux-offline/redux-offline/lib/types

import { NetInfo, NetworkCallback } from '@redux-offline/redux-offline/lib/types';
Run Code Online (Sandbox Code Playgroud)

然后在typings.d.ts我刚刚添加:

declare module '@redux-offline/redux-offline/lib/types' {
  export type NetInfo = any;
  export type NetworkCallback = any;
}
Run Code Online (Sandbox Code Playgroud)

问题就解决了。