流不相交联合检查适用于文字字符串,但不适用于常量

时间:2019-06-20 16:30:02

标签: flowtype

我正在尝试使用Flow正确键入redux动作,但是在使用常量作为动作类型时,它没有正确地检查不连续类型。

我在很多地方都读到这是正确的方法,但是我无法获取// @flow export const INCREMENT: 'INCREMENT' = 'INCREMENT'; export type IncrementAction = {| type: typeof INCREMENT, |}; export const DECREMENT: 'DECREMENT' = 'DECREMENT'; export type DecrementAction = {| type: typeof DECREMENT, |}; export const DOUBLE: 'DOUBLE' = 'DOUBLE'; export type DoubleAction = {| type: typeof DOUBLE, |}; // Notice I didn't include DoubleAction export type Action = IncrementAction | DecrementAction; type State = {| counter: number, |}; export const reducer = (state: State, action: Action): State => { switch (action.type) { case INCREMENT: return { counter: state.counter + 1 }; case DECREMENT: return { counter: state.counter - 1 }; // This case should fail because it's in none of the actions in the disjoint union case DOUBLE: return { counter: state.counter * 2 }; // This case does fail because it's a literal instead of a constants case 'TRIPLE': return { counter: state.counter * 3 }; default: return state; } }; 常量来出错(因此,这实际上并不是正确键入switch语句)。

还有另一种方法吗?

private void giderBtn_Click(object sender, EventArgs e)
    {
        giderPnl.Visible = true; gelirPnl.Visible = false;
        this.GiderTableAdapter.Fill(this.giderDS.Gider);
        ReportDataSource r = new ReportDataSource("DataSet1", giderDS.Tables[0]);
        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.DataSources.Add(r);
        this.reportViewer1.LocalReport.ReportEmbeddedResource = "GelirGiderYonetimi.giderRapor.rdlc";
        this.reportViewer1.LocalReport.Refresh();
        this.reportViewer1.RefreshReport();
    }

    private void gelirBtn_Click(object sender, EventArgs e)
    {
        giderPnl.Visible = false; gelirPnl.Visible = true;
        this.GelirTableAdapter.Fill(this.gelirDS.Gelir);

        ReportDataSource r = new ReportDataSource("DataSet1", gelirDS.Tables[0]);
        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.DataSources.Add(r);
        this.reportViewer1.LocalReport.ReportEmbeddedResource = "GelirGiderYonetimi.gelirRapor.rdlc";
        this.reportViewer1.LocalReport.Refresh();
        this.reportViewer1.RefreshReport();
    }

0 个答案:

没有答案