1

I want to achieve a conceptually simple thing: transform a map of functions that return any (or, for the sake of the example, number) to a map of functions that return void, while conserving the other type information.

Expressed in code, I would like to do something like this:

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)
DanielM
  • 1,106
  • 3
  • 17
  • 27

0 Answers0