打字稿减速机问题

亚历山德罗

我有以下内容:

...

type RepairsState = {
  data: Property[] /* Property is an object coming from another file */
}

type RepairsPropertyLoadAction = {
  type: typeof REPAIRS_PROPERTY_LOAD
  payload: { models: Property[] } /* the payload will return an object that has a models property of an array of objects that match my property type */
}

/* Reducer */
export const initialState: RepairsState = {
  data: [
    {
      id: '',
      jobNo: '',
      trade: '', 
      priority: '',
      status: '',
      raisedDate: new Date(),
      appointmentDate: new Date(), 
      completedDate: new Date(),
      description: ''
    }
  ]
}

export default function reducer(state = initialState, action: RepairsPropertyLoadAction): RepairsState {
  switch (action.type) {
    case REPAIRS_PROPERTY_LOAD:
      console.log(action.payload)
      return {
        ...state,
        data: action.payload
      }
    default:
      return state
  }
}

export const getRepairsProperty = (state: AppState) => state.repairs.data

...

Property 类:

export default class Property {
  id: string = ''
  jobNo: string = ''
  trade: string = ''
  priority: string = ''
  status: string = ''
  raisedDate: Date = new Date()
  appointmentDate: Date = new Date()
  completedDate: Date = new Date()
  description: string = ''
}

但是我收到以下错误:

Type '{ models: Property[]; }' is missing the following properties from type 'Property[]': length, pop, push, concat, and 28 more. TS2740

在此处输入图片说明

亚力山大

该操作返回数据的{models:Property []}对象,但状态具有数据:Property []

return {
   ...state,
   data: action.payload.model
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章