niieani / typescript-vs-flowtype

Differences between Flowtype and TypeScript -- syntax and usability

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infinite loop detection

goodmind opened this issue · comments

Where should I add something like this?

TypeScript:

function hello(): never { // ok
  while(true) {}
}

Flow:

function hello(): empty { // error, void is incompatible with empty
   while(true) {}
}

Something's not right with these examples, @goodmind. An empty function returns void, not empty, so you'll get exactly the same error regardless the function's contents. Example.

I don't think the TypeScript example is right either. The meaning of never is actually that the function will never return - which is exactly what would happen. So even if TS had infinite loop protection, the result of hello should be never rather than void. In fact, if you do the opposite, TS complains.

Not empty functions, with while(true) loop

Flow

TS

TS is right here, because this function never returns, not returns void. I'm asking where should I add this comparison in README

Ah, I see. Yeah, I think it makes sense to add this. Perhaps a new section on behavior differences, since this is not syntax-specific? Thanks!