- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想使用 redux-localstorage npm 模块将 redux stora 保存在本地存储中。问题出在 TypeScript 上,因为 redux-localstorage 没有类型定义。
所以我在 redux-localstorage.ts
中写了自定义类型定义:
declare module 'redux-localstorage' {
module ReduxLocalStorage {
export function persistState<A> (): any;
}
export = ReduxLocalStorage;
}
当我在 store.ts
中创建一个 redux store 时:
import { createStore, applyMiddleware, compose } from "redux";
import { syncHistoryWithStore, routerMiddleware } from "react-router-redux";
import { persistState } from "redux-localstorage";
import { browserHistory } from "react-router";
// Middleware
import logger from "./middleware/logger";
let ReduxThunk = require("redux-thunk").default;
// Reducers
import reducers from "./reducers/main";
export default function configureStore() {
const createStoreWithMiddleware: any = compose(
applyMiddleware(
ReduxThunk,
logger,
routerMiddleware(browserHistory)
),
persistState(),
window.devToolsExtension ? window.devToolsExtension() : f => f
)(createStore);
const store = createStoreWithMiddleware(reducers);
return {
store,
history: syncHistoryWithStore(browserHistory, store)
};
}
当我编译项目时,一切似乎都很好,但是当我尝试在 Chrome 中加载我的应用程序时,出现以下错误:
store.ts:21 Uncaught TypeError: redux_localstorage_1.persistState is not a function(…)configureStore @ store.ts:21(anonymous function) @ main.tsx:23__webpack_require__ @ bootstrap a9a3afb…:50(anonymous function) @ main.bundle.js?a9a3afb…:6__webpack_require__ @ bootstrap a9a3afb…:50webpackJsonpCallback @ bootstrap a9a3afb…:21(anonymous function) @ main.bundle.js?a9a3afb…:1
打字声明似乎至少以某种方式起作用,就像在我编写 redux-localstorage.ts
定义之前一样,我在项目构建时遇到以下错误:./src/store.ts 中的错误
(3,30):错误 TS2307:找不到模块“redux-localstorage”。
最佳答案
代替:
import { persistState } from "redux-localstorage";
尝试
import * as persistState from "redux-localstorage";
此外,您不需要创建类型定义文件...
关于redux-localstorage 的 TypeScript 类型问题,persistState 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41166630/
我是 Angular 新手。使用 $localstorage(ngStorage) 是否有任何特定的原因而不是常规的 javascript localstorage 有什么区别。 谁能给我解释一下吗?
这个问题说明了一切。我意识到所有选项都可以在最新的浏览器中使用,但是语义上最好的选择是什么?为什么? 最佳答案 根据 W3C 标准,正确的是 window.localStorage,因为 localS
我想不出一个好的标题,所以希望可以。 我正在做的是创建一个离线 HTML5 webapp。 “出于某些原因”我不希望将某些文件放在缓存 list 中,而是希望将内容放在 localStorage 中。
我最近问了a question about LocalStorage .使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
我最近问了a question about LocalStorage .使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
我最近问过a question about LocalStorage 。使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
我在将本地存储的定价添加到其他字段时遇到问题。如果我将 beforeNoonNPSlot 的价格设置为 2,但我将 matineeNPSlot 的字段留空(它应该保留分配给的任何价格)最后)。然后在我
我需要从 localStorage 对象变量中删除对象键而不从 localStorage 中删除键 let obj = localStorage; let keys = Object.keys(loc
根据我所读到的内容,我希望以下代码能够工作。 此代码是函数的一部分,该函数应该通过用下一个更高的 localStorage 变量覆盖它来删除 localStorage 变量。一旦没有更多内容可供复制,
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: JavaScript property access: dot notation vs. brackets? 我是
编写localStorage['key'] = value或localStorage.setItem('key', value)有区别吗? 我看到了this question标记为重复,但在开发人员工
我一直在做以下事情: var store = window.localStorage; store.setItem() 但现在我看到代码是这样做的: localStorage.setItem() 两者
我在 Chrome 上遇到此错误。不知道为什么会发生。任何帮助!我正在使用 Backbone.localStorage 插件和 Backbone。我在以下行中收到错误: localStorage: B
如果我尝试以下代码: var c = new Backbone.Collection(); c.localStorage = new Backbone.LocalStorage("items");
我想使用 localStorage 存储用户输入值,然后在倒计时器中使用该值。 这是用户输入数据的 HTML: Work Time
我有一个适用于 Mac 和 Linux 用户但不适用于 Windows 用户的 Chrome 扩展程序。当我进入控制台并在 localStorage 中设置一个项目时,它工作正常,但是当用户尝试使用扩
在这里浏览所有问题/答案,但找不到解决我的问题的方法。条件('localStorage' in window)返回 true但是 localStorage 的对象本身仍然是 undefined . 设
使用下面的代码,我创建一个 localstorage 变量,如果未定义,则其键为 quote = 1。然而,当最终使用相同的引号键再次调用它时,即使使用了 Number() 函数,它也会变成 11 而
我上次检查时,以下两行返回 true: null == localStorage["foo"]; null == localStorage.getItem("foo"); 将 null 替换为 und
我正在尝试在 NextJS 静态站点上使用 localStorage,但遇到 localStorage 未定义错误。 我的错误显示组件的代码是: export default function Cat
我是一名优秀的程序员,十分优秀!