type Actions =
| ['add', number, number] // should return number
| ['log', string]; // should return void
type Call = (...args: Actions) => Promise<?>;
const call: Call = (...args: Actions): Promise<?> => {
// returns some Promise
}
call('add', 1, 1).then(value => {
// value is then inferred as number
})
call('log', 'Hello World!').then(value => {
// value is then inferred as void
})
Run Code Online (Sandbox Code Playgroud)
你如何根据传递给函数的任何参数来确定 Promise 的返回值?