如何提取嵌套类型?

How to extract a nested type?

我导入了一个名为 IFoo

的接口
interface IFoo {
  name: string;
  version: number;
  init: (arg1: string, arg2: number) => Promise<string[]>;
}

我只关心 init 的类型 有没有办法提取它以便我可以在其他地方使用此接口?即

inteface ICustom {
  properties: {
    group: string,
    init: IFoo.init
  }
  amount: number
}

您可以使用索引访问类型:

interface IFoo {
  name: string;
  version: number;
  init: (arg1: string, arg2: number) => Promise<string[]>;
}

interface ICustom {
  properties: {
    group: string,
    init: IFoo["init"]
  }
  amount: number
}