Breaking Changes:
- Flowconfig option
experimental.assertion_functionsis removed. Assertion functions have been on by default and the option only acceptedtruesince 0.337. - Flowconfig option
experimental.disable_invariant_special_casingis removed. It has been on by default and only acceptedtruesince 0.337. - Flowconfig option
experimental.function_and_object_type_is_no_longer_anyis removed. It has been on by default and only acceptedtruefor a while. - Flowconfig option
experimental.builtin_ts_libdef_dynamic_discoveryis removed. It has been on by default and only acceptedtrue. - Flowconfig option
experimental.declare_global_supportis removed. It has been on by default and only acceptedtrue.
Likely to cause new Flow errors:
Readonly,Partial,Required,$Exact,Omitand mapped types over an interface now include its methods and the members it inherits.- Type guards now refine
Array<any>,{data: any},Map<string, any>and similar types to the guarded type, e.g.Array<string>, which can surface errors in code that relied onany. - Static members can no longer reference the type parameters of their class, like in TypeScript, and reading a static member of a generic class no longer infers them.
keyofof an object with a template literal indexer no longer widens the indexer key tostringin conditional types likeExclude.
New Features:
- Mapped types over arrays and tuples support
readonlyandwriteonlymodifiers. - Property truthiness checks such as
if (result.done)now refine unions of classes and interfaces by fields with literal types, as===checks already did. - Type guards narrow through optional calls such as
isString?.(x). When the callee or receiver is nullable, only the true branch narrows. - Support optional assertion calls when their declared types guarantee the call runs.
- Added the intrinsic
ExactObjectType, the supertype of every exact object type and a subtype of{...}.
Notable bug fixes:
- Fix crashes and false recursive-definition errors from cyclic type star exports in TypeScript declarations.
- Support namespace export aliases and ambient exported members in TypeScript definitions.
- Allow classes to extend a constructor whose overloads are not all generic, such as
Uint8Array<ArrayBuffer>. - Casting a value whose type intersects an enum with other types (e.g.
E & E) to the enum's representation type no longer errors. - Arrays can be assigned to variables and parameters whose type was inferred from
new Array<T>(...). - Report delegated yield type errors at the yield expression.
- Align Try Flow's default lints and
declare globalsupport with regular Flow. - Improve inference for generic values passed to polymorphic operations.
- Fix Try Flow initialization after the async builtin migration while preserving older releases' library definitions.
- Report conditional type instantiation errors at the caller.
- Apply type-parameter defaults when omitted optional or nullable arguments are the only evidence for them.
- An object with an indexer is no longer checked against optional properties it doesn't declare of a TypeScript-declared (
.d.ts) object type, matching TypeScript. - Fewer
underconstrained-implicit-instantiationerrors for generic calls passed as arguments to other generic calls. - Fixed a crash when printing long types that contain non-ASCII names in error messages.
- Tuple types with a spread keep the variance of their own elements, e.g.
ain[readonly a: unknown, ...T]stays read-only. Firstin[infer First, ...infer Rest]is now inferred instead ofunknown.- Fixed a deadlock in the Flow server monitor that could make all subsequent commands fail with "Out of retries, exiting!".
- Type guards with a union type now refine union members precisely, e.g. a falsy-value guard on
string | numberrefines to"" | 0. - Type guards now drop union members that are instances of classes unrelated to the guarded class, e.g.
x: A | Brefined byx is Ais nowArather thanA | (A & B). - The negative branch of a type guard now refines away generics that satisfy the guard, e.g.
x: T | numberrefined by!isT(x)withisT: (x: unknown) => x is Tis nownumber. - In the negative branch of a type guard,
anynow staysanyinstead of becomingempty, andbooleanis refined to the literal the guard does not cover. - Correct stdin behavior for
flow check-contentsandflow autocomplete. - Error messages print code that contains backticks, such as template literals, as markdown code spans.
- Instances of TypeScript-declared generics, such as
React.MouseEvent<T>, now compare type parameters without a variance annotation covariantly, as type applications already did. - Type guards now drop tuple members of a different length and array members with disjoint element types.
- Type guards now drop object and interface union members whose properties conflict with the guard type.
x instanceof Cno longer refines a value of an intersection type toempty.- Linux release builds use jemalloc, which keeps the memory of long-running servers from growing after large rechecks.
- Fixed a race that could leave a file unmerged after a recheck, which made the server recheck forever while an open file imported it.
Misc:
- Print rest arrays as array types in errors.
- Print receiver and merged declaration types in errors.
- Simplify missing this annotation diagnostics.
- Print both types in inheritance errors.
- Identify missing parameter annotations directly at the parameter location.
- Remove empty filename metadata from the Try Flow AST display.
- Add a default-on option to hide locations in the Try Flow AST pane.
- Show node types first in the Try Flow AST pane.
- Add a default-on option to hide null and undefined fields in the Try Flow AST pane.
- Move Try Flow's JSON error output into an Errors format pill bar.
- Add JSON AST output to Try Flow.
Parser:
- Accept explicit semicolons on shorthand ambient modules.
- Accept keyword members in qualified type names and import types.
- Allow repeated inline interface exports in TypeScript files.
- Fixed
flow-parsertaking minutes to parse JS files over ~1 MB. - Support destructured rest parameters in function type signatures.
- Support import attributes on re-export declarations.
- Preserve TypeScript accessibility modifiers on bodyless class method signatures.
- Preserve computed type-literal keys as properties in TypeScript source files.
- Allow newline-separated type members in TypeScript source files.
- Use
"in out"for the ESTree variance kind ofin outtype parameters. - Parse postfix non-null assertions with type syntax enabled, preserve ASI, and emit TypeScript-compatible
NonNullExpressionnodes. - Respect JavaScript line terminators and Unicode whitespace when recovering source locations.
- Parse default interface exports and report unsupported syntax during type checking.
- Correct inferred ESTree source type for default interfaces, inline type specifiers, and exported import aliases.
- Exclude default interface exports and all-type specifier lists from inferred Babel module source type.
- Support top-level await for explicit modules and
.mjs/.mtsfiles in flow-parser. - Always enable type parsing for TypeScript filenames.
- Reject type syntax in untyped parser mode and report precise diagnostics.
- Fix declaration method signature locations to include the complete signature.
- Include the
constkeyword in const enum declaration locations.
IDE:
- Hover and error messages no longer print redundant parentheses around function types in maybe types, e.g.
?() => voidinstead of?(() => void).
Library Definitions:
- Align well-known symbol members (
Symbol.toStringTag,Symbol.match,Symbol.toPrimitive, ...) with TypeScript. MapandWeakMapset, andSetandWeakSetadd, now returnthis.RegExpflags/sticky/unicodeandNumber.EPSILON/MAX_SAFE_INTEGER/MIN_SAFE_INTEGERare now read-only;String.prototype.normalizeaccepts the normalization form literals and the legacy HTML methods (bold,link, ...) are declared.Array.prototype.copyWithinreturnsthis, so subclasses ofArraykeep their type.Array.prototype.sortreturnsthis, so subclasses ofArraykeep their type.Mathconstants (Math.PI,Math.E, ...) are read-only.Number.MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITYandPOSITIVE_INFINITYare read-only.String#splitrequires a separator,String#replacehas separate overloads for a string and a function replacement, andString#lengthis read-only, as in TypeScript.- Use TypeScript's ES2018 async iterator and iterable definitions.
- Use TypeScript's ES2018 async generator definitions.
- Use TypeScript's ES2019 array definitions while preserving Flow's existing
flatMapunion order and inference. - Use TypeScript's ES2020 promise definitions, including mutable settled results.
- Use TypeScript's ES2016 array
includesdefinitions while keeping Flow's element refinement. - Use TypeScript's ES2015 generator definitions.
Generator.prototype.returnnow requires a value of the generator's return type. - Add
React.CSSProperties, typed bycsstype. - Use TypeScript's ES2015 promise definitions, adapted to Flow's inference.
- Use TypeScript's ESNext set method definitions, including
Set.prototype.union. - Use TypeScript's ES2015
Map,Set,WeakMapandWeakSetdefinitions.sizeis now read-only. doneis now optional in the non-final branch ofIteratorResult, as in TypeScript.- Use TypeScript's ES2015 iterable definitions.
ArrayIterator,MapIterator,SetIteratorandStringIteratorare now interfaces, andStringIteratortakes a type argument. - Add React's DOM types from
@types/react, such asReact.MouseEvent,React.HTMLAttributesandReact.JSX.IntrinsicElements. React.ComponentPropsof a string that is not a JSX intrinsic isemptyin roots that define their own$JSXIntrinsics.- Use TypeScript's ESNext iterator helper definitions.
reducewithout an initial value now requires the reducer to return the iterator's element type. Array,ReadonlyArrayand typed arraytoLocaleStringnow accept locales and formatting options.- Use TypeScript's ES2015 core definitions.