niieani / typescript-vs-flowtype

Differences between Flowtype and TypeScript -- syntax and usability
MIT License
1.74k stars 78 forks source link

Infinite loop detection #56

Open goodmind opened 5 years ago

goodmind commented 5 years ago

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) {}
}
niieani commented 5 years ago

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.

goodmind commented 5 years ago

Not empty functions, with while(true) loop

goodmind commented 5 years ago

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

niieani commented 5 years ago

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!