2017-06-29 29 views
3

我想從流文字類型的包中使用導入的常量並靜態檢查開關;定義流文字類型時使用外部常量

有沒有辦法做到這一點? (實施例波紋管)

// action/types.js 
import { REHYDRATE } from 'redux-persist/constants' 

export type FooBar = { 
    foo: number, 
    bar: string, 
}; 

export type Action 
    = { type: 'FETCH_REQUEST', data: FooBar[] } 
    | { type: REHYDRATE, payload: any } // <== this do not work 
    ; 

// reducer.js 
import { REHYDRATE } from 'redux-persist/constants' 

export default function (state: State = initialState, action: Action) 
    switch (action.type) { 
    case 'FETCH_REQUEST': 
     // do something with action.data 
    case REHYDRATE: { // <= flow says: uncovered code 
     // do something with action.payload 
    default: 
     return state 
    } 
} 

回答

4

Flow不支持使用的含有在類型定義常量變量。

您必須在定義中使用字符串值本身或支持數據類型。

This post是一個類似的問題,如果你想要查看它也是如此。