gpt4 book ai didi

reactjs - 如何将 redux-persist 添加到 typescript 项目?

转载 作者:行者123 更新时间:2023-12-03 14:32:38 26 4
gpt4 key购买 nike

我正在尝试将 redux-persist 添加到我的 React 项目中(使用 typescript)。但我有一些麻烦。编译失败,出现以下错误:

Could not find a declaration file for module 'redux-persist/lib/storage'. '.../WebstormProjects/catalog/node_modules/redux-persist/lib/storage/index.js' implicitly has an 'any' type.
Try `npm install @types/redux-persist` if it exists or add a new declaration (.d.ts) file containing `declare module 'redux-persist/lib/storage'

我安装了以下软件包:“@types/redux-persist”:“^4.3.1”和“redux-persist”:“^6.0.0”。

redux-persist/lib/storage 的内容:
declare module "redux-persist/es/storage" {
import { WebStorage } from "redux-persist/es/types";

const localStorage: WebStorage;
export default localStorage;
}

declare module "redux-persist/lib/storage" {
export * from "redux-persist/es/storage";
export { default } from "redux-persist/es/storage";
}

怎么做才能解决这个问题?

最佳答案

添加这一行:

/// <reference types="redux-persist" />
react-app-env.d.ts 如果您使用 创建 react 应用程序 .

关于reactjs - 如何将 redux-persist 添加到 typescript 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59874937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com