2017-05-29 12 views
1

私はこのようなものがあります:活字体識別型連合型

export const MapDispatchToProps = { 
    currentDateChanged, 
    attendanceReceived, 
    updateRecord, 
    updateRecords, 
}; 

export type ActionsType = typeof currentDateChanged | typeof attendanceReceived | typeof updateRecord | typeof updateRecords; 

をMapDispatchToPropsの性質を繰り返すことなく、判別共用体型のActionsTypeを定義する方法はありますか?

答えて

1

もっとクリーンな方法があるのか​​どうかわかりませんが、技術的に可能です。

const garbage = (<T>(o: {[key: string]: T}): T => undefined!)(MapDispatchToProps); 

export type ActionsType = typeof garbage; 
:(私の知る限り管理できるよう)凝縮

function f<T>(o: {[key: string]: T}): T { 
    return undefined!; 
} 

const garbage = f(MapDispatchToProps); 

export type ActionsType = typeof garbage; 

関連する問題