A dam with mountains in the background
A dam with mountains in the background
Photo by ciboulette from Pexels

tl;dr: Flow has improved its handling of generic types by banning unsafe behaviors previously allowed and clarifying error messages.

We’ve improved Flow’s ability to detect errors in generic function and class definitions, and also introduced a new restriction on how generic types can be used. This post describes the new restriction and how to upgrade.

The escaped-generics restriction

let external_var = 42;
function f<T>(x: T, should_escape: bool): T | number {
if (should_escape) {
external_var = x;
}
return external_var;
}

Since it’s unannotated, Flow will infer the type of external_var, and find it to be T…

Michael Matson Vitousek

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store