How to define a function which cannot return anything in TypeScript

前端 未结 1 1283
栀梦
栀梦 2020-12-22 08:15

I am writing an API which has 2, very similar, functions:

function update(f: () => string) {...}
function updateDeep(f: () => void) {...}
相关标签:
1条回答
  • 2020-12-22 08:45

    It isn't possible to make this happen. As the recipient of a function, your only ability is to set a lower bound on what kind function is provided.

    See also the TypeScript FAQ entry: https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-functions-returning-non-void-assignable-to-function-returning-void

    0 讨论(0)
提交回复
热议问题