isolatedDeclarations and Control Flow Analysis
microsoft/typescript-go#4367
- Want to be able to infer types for trivial expressions in
isolatedDeclarations in a function block.
- Specifically in discussion is if there are no return statements.
- But what happpens when you have a
never-returning call? That can cause a never.
- Feels like anything with multiple statements in the body is questionable.
- We could make a special-case for
() => {}.
- Probably enough to just say "just write
void".
- Feels bad to say we can't come up with a type for
() => {}
- Why? Feels like it's not a big deal?
- Well it's even more trivial than a single expression being returned.
- Sure, but the reason we added trivial expression inference was because people often have bigger structures of objects that are nested. So the triviality was not really about writing small expressions.
- One reason why we didn't do it (we think) is that we don't want to close the door to ourselves on how
void vs. undefined is inferred for no-return-expression functions.
isolatedDeclarationsand Control Flow Analysismicrosoft/typescript-go#4367
isolatedDeclarationsin a function block.never-returning call? That can cause anever.() => {}.void".() => {}voidvs.undefinedis inferred for no-return-expression functions.