How can I ensure a function always returns a value in TypeScript?
Due to the fact that void
is a subtype of any
, I haven't been able to find any generics that successfully exclude void
from any
.
My current workaround looks like this:
type NotVoid = { [key: string]: NotVoid } | object | string | boolean | symbol | number | null | undefined
The solution above seems quite lengthy. Is there a more concise way to achieve this?
I am aware of a proposal for negation, but I need a solution today using TypeScript specifically, not just a linting rule. Thank you!