Javascript 在不相交的并集类型中找不到属性
以下代码:Javascript 在不相交的并集类型中找不到属性,javascript,flowtype,Javascript,Flowtype,以下代码: /* @flow */ type StepApplicationAction = { type: "STEP_APPLICATION" } type RewindApplicationAction = { type: "REWIND_APPLICATION" } type ApplicationAction = StepApplicationAction | RewindApplicationAction type RequestVinsAction = { type: "RE
/* @flow */
type StepApplicationAction = { type: "STEP_APPLICATION" }
type RewindApplicationAction = { type: "REWIND_APPLICATION" }
type ApplicationAction = StepApplicationAction | RewindApplicationAction
type RequestVinsAction = { type: "REQUEST_VINS" }
type ReceiveVinsAction = { type: "RECEIVE_VINS", vins: Array<string> }
type VehicleAction = RequestVinsAction | ReceiveVinsAction
type Action = ApplicationAction | VehicleAction
function reducer(action: Action) {
switch (action.type) {
case "REQUEST_VINS": console.log('HERE')
case "RECEIVE_VINS":
console.log(action.vins)
default:
return
}
}
不确定本例中我的不相交并集设置有什么问题。您忘记了从case分支中返回
或中断
:
/* @flow */
type StepApplicationAction = { type: "STEP_APPLICATION" }
type RewindApplicationAction = { type: "REWIND_APPLICATION" }
type ApplicationAction = StepApplicationAction | RewindApplicationAction
type RequestVinsAction = { type: "REQUEST_VINS" }
type ReceiveVinsAction = { type: "RECEIVE_VINS", vins: Array<string> }
type VehicleAction = RequestVinsAction | ReceiveVinsAction
type Action = ApplicationAction | VehicleAction
function reducer(action: Action) {
switch (action.type) {
case "REQUEST_VINS": console.log('HERE'); return;
// ^^^^^^^
case "RECEIVE_VINS":
console.log(action.vins); return;
default:
return;
}
}
/*@flow*/
类型StepApplicationAction={type:“STEP_应用程序”}
类型RewindApplicationAction={type:“REWIND_应用程序”}
类型ApplicationAction=步骤ApplicationAction |倒带ApplicationAction
类型RequestVinsAction={type:“REQUEST_VINS”}
type ReceiveVinsAction={type:“RECEIVE_VINS”,VINS:Array}
类型VehicleAction=RequestVinsAction | ReceiveVinsAction
类型动作=应用动作|车辆动作
功能减速机(动作:动作){
开关(动作类型){
案例“REQUEST_VINS”:console.log('HERE');return;
// ^^^^^^^
“接收”案例:
console.log(action.vins);返回;
违约:
返回;
}
}
您忘记了从案例分支中返回或中断:
/* @flow */
type StepApplicationAction = { type: "STEP_APPLICATION" }
type RewindApplicationAction = { type: "REWIND_APPLICATION" }
type ApplicationAction = StepApplicationAction | RewindApplicationAction
type RequestVinsAction = { type: "REQUEST_VINS" }
type ReceiveVinsAction = { type: "RECEIVE_VINS", vins: Array<string> }
type VehicleAction = RequestVinsAction | ReceiveVinsAction
type Action = ApplicationAction | VehicleAction
function reducer(action: Action) {
switch (action.type) {
case "REQUEST_VINS": console.log('HERE'); return;
// ^^^^^^^
case "RECEIVE_VINS":
console.log(action.vins); return;
default:
return;
}
}
/*@flow*/
类型StepApplicationAction={type:“STEP_应用程序”}
类型RewindApplicationAction={type:“REWIND_应用程序”}
类型ApplicationAction=步骤ApplicationAction |倒带ApplicationAction
类型RequestVinsAction={type:“REQUEST_VINS”}
type ReceiveVinsAction={type:“RECEIVE_VINS”,VINS:Array}
类型VehicleAction=RequestVinsAction | ReceiveVinsAction
类型动作=应用动作|车辆动作
功能减速机(动作:动作){
开关(动作类型){
案例“REQUEST_VINS”:console.log('HERE');return;
// ^^^^^^^
“接收”案例:
console.log(action.vins);返回;
违约:
返回;
}
}