帮忙看下这个函数参数是怎么传的,这是啥写法。

const helloReducer = (state: Immut = initialState, action: { type: string, payload: any }) => {
  switch (action.type) {
    case SAY_HELLO:
      return state.set('message', action.payload)
    default:
      return state
  }
}

(state: Immut = initialState, action: { type: string, payload: any }) 这个参数是什么写法?解构也不长这个样子啊?
跪求答案?

阅读 2.5k
3 个回答

这是typescript或者flow的语法
写成js的话就是这样

const helloReducer = (state = initialState, action) => {
    /*...*/
}

冒号后面指定的类型是用于编译期检查参数类型的

应该是React Redux

对象解构。

helloReducer(1, { type: '1', payload:2 });
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题