While diving into TypeScript for the first time, I encountered error TS2339
as I attempted to create a typed redux reducer. The error message is as follows:
https://i.sstatic.net/UyRM0.png
Am I missing something in my usage of the typescript pipe operator? Appreciate any guidance!
sampleActionTypes.ts:
export interface Data {
allIds?: number[];
byId?: object;
}
interface IncrementCount {
type: string;
}
interface ReceiveData {
type: string;
data: Data;
}
export type SampleActionTypes = ReceiveData | IncrementCount;
sampleReducer.ts:
export interface SampleState {
count: number;
data: Data;
}
const initialState = {
count: 0,
data: {},
};
const sample = (state = initialState, action: SampleActionTypes): SampleState => {
switch (action.type) {
case 'INCREMENT_COUNT': {
const newCount = state.count + 1;
return {
...state,
count: newCount,
};
}
case 'RECEIVE_DATA':
return {
...state,
data: action.data, // encountering an error at this point
};
default:
return state;
}
};
export default sample;