是否可以将回调函数参数定义为命名空间接口?

Is it possible to define a callback function parameter as a namespaced interface?

我正在为一组特定于应用程序的 API 创建一些智能感知,我很好奇是否可以将回调函数的参数定义为先前定义的接口?我担心我什至无法正确地提出这个问题,所以我只会向您展示代码。

我有一个 definitelyTyped 文件,其中包含我的打字稿定义的智能感知。它很长,所以我只展示相关的内容。

declare interface N_search {
    create: {
        (options: {
            type: string
        }): N_search.Search
}

declare namespace N_search {

    interface Search {
        run(): N_search.ResultSet
    }
    interface Result {
        type: string
        id: number
    }
    interface ResultSet {
        each: {
            (callback (N_search.Result)) : void //aware this is not correct...
    }

可能很难从混乱中收集到,但接口 ResultSet 内部的(回调)是一个函数。该函数的参数是一个 N_search.Result 对象,我希望智能感知显示它。这是 javascript 我正在寻找的 intellisense。

var search = N_search.create(options);

search.run().each(function (result) {
    result. /* I want intellisense here to show the N_search.Result object
      which should be type: string  ;  id: number */
});

我希望我的问题有道理,非常感谢任何帮助!

定义您的 ResultSet 接口,如:

interface ResultSet {
    each: (callback: (result: N_search.Result) => void) => void        
}