打字稿:尝试为 redux 商店构建自动完成

时间:2021-05-05 12:59:37

标签: typescript

我已经尝试了 4 个小时,但仍然什么都没有! Redux 有一些自动完成功能,例如: store.getState().test.hello 我正在努力实现类似的目标。 测试减速器:

const initialState = {
    hello: "adssad",
};

export default (state = initialState, action) => {
    switch (action.type) {
    }
    return state;
};

我创建了两个函数,它们现在分两步自动完成,但无法做到一个。

export const testSSS = <R>(reducer: Reducer<R, any>): R => {
    return null;
};

export const testSSSS = <R, K>(reducers: R, key: keyof R) => {
    const reducer = reducers[key];
    return null as Reducer<typeof reducer, any>;
};

这是他们所做的:

    const test = testSSSS(
        {
            test: testReducer,
        },
        "test"// <--- this has auto completion
    );
testSSS(testReducer)
    .hello; <--- this has auto completion

0 个答案:

没有答案