我在手动创建的.d.ts文件中有此类型脚本代码:

export interface IBeforeHook {
     foo: Function,
     bar: Function
}


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

type TBeforeHookTemp =
  BeforeHookCallbackMode |
  BeforeHookRegularMode |
  BeforeHookObservableMode |
  BeforeHookSubscriberMode |
  BeforeHookEEMode

我希望所有的tbeforehook类型都能扩展/实现ibeforehook接口……我该怎么做呢?
我想做的事情是:
export type TBeforeHook extends TBeforeHookTemp implements IBeforeHook {

}

但那不管用。

最佳答案

您可以定义一个intersection type

export type TBeforeHook = TBeforeHookTemp & IBeforeHook;

09-19 04:45