Wednesday, 19 April 2017

Four different function signatures, encapsulate with one parent type

I have these four different function signatures:

type BeforeHookCallbackMode = (h: IBeforeHook) => void;
type BeforeHookRegularMode = (h?: IBeforeHook) => Promise<any>;
type BeforeHookObservableMode = (h?: IBeforeHook) => Observable<any>;
type BeforeHookEEMode = (h?: IBeforeHook) => EventEmitter;

How can I create a parent type, from which these 4 types inherit? So that I can use that parent type in a function signature, instead of doing:

function(fn : BeforeHookCallbackMode | BeforeHookRegularMode | BeforeHookObservableMode | BeforeHookEEMode) {


}



via Alexander Mills

No comments:

Post a Comment