I think that typescript has many unobvious places, making it not strict and not correct.
I want use undefined as functions return type. Because in reality it is undefined, not void or some other fictional type. But when I write this:
function myFunction(): undefined {
}
it says "A function whose declared type is neither 'void' nor 'any' must return a value".
It must not. And everyone can verify this. I don't want to agree with "void is better, we decided that promise equal undefined" and so on. And don't want to write return undefined
, if it is obvious and redundant.
How to make it work in this example? May be some flag exist or some "miracle comment instruction"?
Here is the use case, explaining why I want explicit undefined: