undoable TS typing (#2374)

* type undoable-related TS

* style change to type declaration
This commit is contained in:
Bruce Martin
2021-08-12 17:14:09 -07:00
committed by GitHub
parent 925b785b1f
commit 4b417cb5a5
5 changed files with 266 additions and 195 deletions
+8 -9
View File
@@ -1,10 +1,12 @@
import { Reducer } from "redux";
import undoable from "../../src/reducers/undoable";
describe("create", () => {
test("no keys", () => {
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2-3 arguments, but got 1.
expect(() => undoable(() => {})).toThrow();
expect(() => undoable(() => {}, null)).toThrow();
expect(() =>
undoable(() => {}, undefined as unknown as string[])
).toThrow();
expect(() => undoable(() => {}, null as unknown as string[])).toThrow();
expect(() => undoable(() => {}, [])).toThrow();
expect(() => undoable(() => {}, [], {})).toThrow();
});
@@ -24,8 +26,7 @@ describe("create", () => {
describe("undo", () => {
test("expected state modifications", () => {
const initialState = { a: 0, b: 1000 };
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
const reducer = (state: any) => ({ a: state.a + 1, b: state.b + 1 });
const reducer: Reducer = (state) => ({ a: state.a + 1, b: state.b + 1 });
const undoableReducer = undoable(reducer, ["a"]);
const s1 = undoableReducer(initialState, { type: "test" });
@@ -43,10 +44,8 @@ describe("undo", () => {
describe("redo", () => {
const initialState = { a: 0, b: 1000 };
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
const reducer = (state: any) => ({ a: state.a + 1, b: state.b + 1 });
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
let UR: any;
const reducer: Reducer = (state) => ({ a: state.a + 1, b: state.b + 1 });
let UR: Reducer;
beforeEach(() => {
UR = undoable(reducer, ["a"]);