我有这四种不同的功能签名:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="container">
<div id="inner"></div>
</div>
如何创建父类型,这4种类型从哪种类型继承?这样我就可以在函数签名中使用该父类型,而不是:
type BeforeHookCallbackMode = (h: IBeforeHook) => void;
type BeforeHookRegularMode = (h?: IBeforeHook) => Promise<any>;
type BeforeHookObservableMode = (h?: IBeforeHook) => Observable<any>;
type BeforeHookEEMode = (h?: IBeforeHook) => EventEmitter;
答案 0 :(得分:1)
你不是在找父母&#34;类型,但是&#34; union&#34;类型。
type BeforeHookMode = BeforeHookCallbackMode |
BeforeHookRegularMode |
BeforeHookObservableMode |
BeforeHookEEMode;
function (fn: BeforeHookMode) {