У меня есть следующий модульный тест:
it('should handle REPAIRS_PROPERTY_LOAD_SUCCESS', () => {
const result = reducer(initialState, {type: 'repairs/PROPERTY_PAGE_LOAD_SUCCESS'})
expect(result).toEqual({}); /* the test would fail */
})
, но я получаю следующую ошибку:
[ts]
Argument of type '{ type: "repairs/PROPERTY_PAGE_LOAD_SUCCESS"; }' is not assignable to parameter of type 'RepairsAction'.
Type '{ type: "repairs/PROPERTY_PAGE_LOAD_SUCCESS"; }' is not assignable to type 'RepairsPropertyLoadSuccessAction'.
Property 'payload' is missing in type '{ type: "repairs/PROPERTY_PAGE_LOAD_SUCCESS"; }'.
, и мой файл редуктора выглядит следующим образом:
...
/* Actions & action types */
const REPAIRS_PROPERTY_LOAD = 'repairs/PROPERTY_PAGE_LOAD'
const REPAIRS_PROPERTY_LOAD_SUCCESS = 'repairs/PROPERTY_PAGE_LOAD_SUCCESS'
const REPAIRS_SEARCH = 'repairs/REPAIRS_SEARCH'
const REPAIRS_SEARCH_SUCCESS = 'repairs/REPAIRS_SEARCH_SUCCESS'
type RepairsPropertyLoadAction = {
type: typeof REPAIRS_PROPERTY_LOAD
}
export type RepairsPropertyLoadSuccessAction = {
type: typeof REPAIRS_PROPERTY_LOAD_SUCCESS
payload: RepairsProperty
}
type RepairsSearchAction = {
type: typeof REPAIRS_SEARCH
}
type RepairsSearchSuccessAction = {
type: typeof REPAIRS_SEARCH_SUCCESS
payload: RepairsProperty
}
export type RepairsAction =
| RepairsPropertyLoadAction
| RepairsPropertyLoadSuccessAction
| RepairsSearchAction
| RepairsSearchSuccessAction
/* Reducer */
export type RepairsState = {
data: Property[]
isFetching: boolean
}
export const initialState: RepairsState = {
data: [
{
id: '',
jobNo: '',
trade: '',
priority: '',
status: '',
raisedDate: '',
appointmentDate: '',
completedDate: '',
description: '',
},
],
isFetching: false,
}
export default function reducer(state = initialState, action: RepairsAction): RepairsState {
switch (action.type) {
case REPAIRS_PROPERTY_LOAD:
case REPAIRS_SEARCH: {
return {
...state,
isFetching: true,
}
}
case REPAIRS_PROPERTY_LOAD_SUCCESS:
case REPAIRS_SEARCH_SUCCESS: {
return {
...state,
isFetching: false,
data: action.payload.models,
}
}
default:
return state
}
}
...
с ремонтом, свойство:
...
export default class Property {
id: string = ''
jobNo: string = ''
trade: string = ''
priority: string = ''
status: string = ''
raisedDate: string = ''
appointmentDate: string = ''
completedDate: string = ''
description: string = ''
}
export class RepairsProperty {
models: Property[] = []
}
...