Typescript:尝试为redux存储构建自动完成
我已经4个小时了,我一直在努力,但还是一无所获! Redux具有一些自动完成功能,如:Typescript:尝试为redux存储构建自动完成,typescript,Typescript,我已经4个小时了,我一直在努力,但还是一无所获! Redux具有一些自动完成功能,如: store.getState().test.hello我正在尝试实现类似的目标。 测试减速器: const initialState = { hello: "adssad", }; export default (state = initialState, action) => { switch (action.type) { } return st
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>;
};
export const testSSS=(reducer:reducer):R=>{
返回null;
};
export const testSSSS=(减速器:R,键:keyof R)=>{
常数减速机=减速机[键];
返回null作为Reducer;
};
他们是这样做的:
const test = testSSSS(
{
test: testReducer,
},
"test"// <--- this has auto completion
);
const test=testSSSS(
{
测试:测试减速器,
},
“测试”//
testSSS(testReducer)
.hello; <--- this has auto completion