1

概念的に単純なことを達成したいのです: を返すany(または、例のために、numberを返す) 関数のマップをvoid、他の型情報を保持しながら、 を返す関数のマップに変換します。

コードで表現すると、次のようなことをしたいと思います。

type Source = {
    [fn: string]: (...args: any[]) => number
}

type Output = {
    [fn: string]: (...args: any[]) => void
}

function proxy(source: Source): Output {
    // Do something with the source...
    return source
}

const result = proxy({
    answerToLifeTheUniverseAndEverything: (question?: string): number => 42
})

// Should work, and the method should be suggested as part of the auto-completion.
result.answerToLifeTheUniverseAndEverything()

// The compiler should complain.
result.answerToLifeTheUniverseAndEverything(false)
4

0 に答える 0