Breaking Changes:
- Rename
typeParameterstotypeArgumentson ESTreeGenericTypeAnnotation,InterfaceExtends, andClassImplements, including WASMflow-parseroutput. Declaration parameters and Babel output retain their existing names. PropertyDescriptorandObject.getOwnPropertyDescriptorare no longer generic. Remove type arguments fromPropertyDescriptor<T>annotations andObject.getOwnPropertyDescriptor<T>(...)calls.
Likely to cause new Flow errors:
- Hook calls in classes now use
react-rule-hook-class, and calls in deeper nested anonymous callbacks inside components or hooks usereact-rule-hook-conditional, instead ofreact-rule-hook. Update suppressions to the new codes. Hook calls directly in class property initializers are also rejected when the enclosing function would otherwise permit them. - Assignments and throws in function or component parameter defaults and destructuring defaults are now treated as conditional, because a default only runs when the value it replaces is
undefined. - Property increments and decrements (
o.x++,o.x--,++o.x, and--o.x) now invalidate narrowings of the property through aliases, as assignments already do. - Reads in an assertion call's condition now use the types at the point where they run, rather than types after the call and its later arguments. This removes false errors and reports reads before a later argument assigns a variable.
break,continue,return, andthrowpaths throughfinallyare no longer dropped. Flow now reports variables left unassigned and narrowings that do not hold on these paths.- Optional class fields (
x?: T, withexperimental.tslib_syntax) now have typeT | void. Reads may returnundefined, and assigningundefinedis allowed. - Type parameters explicitly declared
in outin TypeScript files are now invariant rather than covariant. - Functions named
use*declared in TypeScript files are now treated as hooks. This fixes calls from Flow hook syntax, but calls outside a component or hook can now report Rules of Hooks errors. parseInt,parseFloat, andevalnow require astring;isNaNandisFiniterequire anumber; and builtin Error constructors require astringmessage, matching TypeScript.Object.getOwnPropertyDescriptor,Object.defineProperty,Object.prototype.hasOwnProperty, andObject.prototype.propertyIsEnumerablenow requirePropertyKey(string | number | symbol) keys.PropertyDescriptorMapis also keyed byPropertyKey.DataView.byteLengthandbyteOffset, numeric typed arraybyteLength,byteOffset, andlength, andRegExp.source,global,ignoreCase, andmultilineare now read-only.RegExp.prototype.compilenow requires a pattern.Array.prototype.spliceuses separate removal and insertion overloads, so inserting items requires adeleteCount.ArrayandReadonlyArrayreduceandreduceRightnow have an overload whose initial value and accumulator use the element type. Calls intending a different accumulator type may need an explicit type argument, e.g.reduce<number>(...).Promise.prototype.thenandcatchnow use TypeScript-style signatures.thenhas separate fulfillment and rejection type parameters; calls whose inferred result is unsuitable may need explicit type arguments.RegExpMatchArray.indexandinputare now optional, and its first element is declared as0: string. Check optional fields onmatchresults, and useRegExpExecArrayforexecandmatchAllresults.Error.stackis now optional, matching TypeScript.- Numeric typed array
subarraymethods, includingUint8Array.prototype.subarray, return their corresponding typed array rather thanthis. Subclasses that return their own type should declare their own override.
New Features:
- Format code with Prettier in the Try Flow playground, and copy JSON from its AST view.
- Object type spreads allow optional properties after an object with an indexer. Value spreads retain their existing checks.
- Add
translateFlowTypeToTSTypetoflow-api-translatorfor type-node translation. - Functions with any return type are accepted where a TypeScript-declared function type returning
voidis expected, matching TypeScript. Flow-declared function types retain their existing return checks.
Notable bug fixes:
- Fixed Windows commands such as
flow checkhanging when their output is piped or captured, even after the command exits (#9519). - Preserve imported TypeScript template literal types without requiring
experimental.tslib_syntax. - Type guards refine distinct bigint literal types to
empty, as they already do for string, number, and boolean literals. - Fixed an internal error when a function parameter default always throws; the function is now typed and checked.
- JavaScript objects with extra properties can be checked against TypeScript object types whose index signature applies to only some keys, and against interfaces extending an object type with an index signature.
- Accept literal initializers such as
declare const x = -1. - Improve implicit instantiation through conditional types without
infer, conditional types nested inside distributive conditional types, and type applications that expand to types mentioning the inferred parameters. - Fixed a crash when a mapped type's key has the same name as a type parameter spread in the mapped object type.
- Imports such as
.//fooand..//fooresolve like./fooand../foo. - Prevent stack overflows and spurious internal errors when checking recursive tuple spreads in generic type arguments.
- JavaScript subclasses can override static methods of TypeScript classes with narrower parameters, as on the instance side.
- Fixed a crash on a
matchin unreachable code. - Fixed a crash when a namespace merged with a class or function redeclares one of its members.
- Fixed crashes when a recheck is canceled while checking a component declaration, or when cancellation or a timeout interrupts a type cast from an annotated source.
- Fixed a crash on a method with a
thisparameter in a class expression or a class declared in a callback. - Fixed a crash when a file imports a name that it also declares as a function, component, or hook.
- Fixed crashes when a library definition stops parsing while the server is running, or contains an ignored statement that reads a name, such as
f();. - TypeScript enum checking no longer requires
enums=true. - Fixed a crash ("Non speculating: LimitExceeded") when destructuring a value whose type lookup exceeds the recursion limit.
- A type parameter whose bound mentions another type parameter no longer leaks unresolved into the other parameter's solution.
- A field named
constructor, including TypeScript's['constructor']fields, now typesx.constructorwithout shadowing the constructor used bynewandsuper(). - Named imports work from CommonJS modules whose
module.exportshas multiple call signatures or is an overloaded function merged with a namespace. - Mapped types with template literal keys now produce individual properties when their placeholders resolve to string literals, instead of retaining a template literal indexer. Generic placeholders and unsupported intersection or recursive-alias cases retain their existing behavior.
flow-upgradetransformations preserve type arguments with both legacy and current parser AST fields.
Misc:
- Implements errors print the implemented interface's type and type arguments instead of generic descriptions such as "exports".
- Try Flow disables Clear and Copy code when the editor is empty, keeps the Format button stable as saved-state controls change, and places the AST format selector after its hide options.
- Tooling documentation recommends
flow-parserand Prettier's built-in Flow parser without an external parser plugin.
Parser:
Programsource locations and ranges span the entire input, including whitespace and comments.flow-parserpreserves optionality on constructor parameter properties.- Correct
flow-estreetypes for unannotated object type properties, readonly type operators, combinedin outvariance, optionalProgram.tokens, sparse-array elements, and JSX namespaced attributes. Sparse-array parent repair and traversal preserve holes. - Omit absent
typeoftype arguments from ESTree output, including WASM-decoded nodes and detached builders. - Default interface exports have the correct type-only export kind and AST typings. Type stripping removes the complete export wrapper rather than leaving a dangling
export default. flow-parsertype stripping preserves function parameter defaults and side-effect imports.flow-transformpreserves leading#!lines.flow-eslintscope analysis handles TypeScript parameter properties, class member decorators, anddeclare global.- Type translation preserves readonly array and tuple operands, inline interface bodies, and qualified interface bases.
- Type translation tracks required React imports for JSX-qualified types.
- Strict TypeScript translation rejects unsupported generic indexer keys instead of silently losing qualification or type arguments. Recovering string-API behavior is unchanged.
IDE:
- Hover on calls to polymorphic functions, including functions bound by
const, properties, or parameters, and on construction of polymorphic classes shows the instantiated type arguments. - Multiline unions and intersections in hover types are indented under their annotation, one member per line.
- Hover,
dump-types, and error messages printanywithout its kind, e.g.anyinstead ofany (explicit).
Library Definitions:
encodeURIComponentalso accepts numbers and booleans.Symbol.prototype.valueOfreturnssymbolinstead of?symbol.arguments.calleeandFunction.prototype.callerare typed asFunction, and functionprototypeproperties are typed asany.TemplateStringsArrayis an interface extendingReadonlyArray<string>.- Add
ImportCallOptions,ImportAssertions, andImportAttributesinterfaces. Date.prototype.toStringdeclares aDatereceiver rather than inheriting anObjectreceiver.- Locale-sensitive methods of
String,Number, andDateuse overloads andIntloption types. - Calling
EvalError,RangeError,ReferenceError,SyntaxError,TypeError, orURIErrorreturns its own type rather thanError. JSON.parsereviver andJSON.stringifyreplacer callbacks accept anythisand receive astringkey.JSON.stringifyreturnsstring; its replacer is a function or a read-only array of strings and numbers.- Declare legacy
RegExpstatics such asRegExp.$1andRegExp.lastMatch. ArrayBuffer.isViewis a type guard that refines its argument toArrayBufferView.ArrayBufferViewis a structural interface rather than a union of typed arrays andDataView. Libraries can extendArrayBufferTypesto add buffer types toArrayBufferLike.- Add
PromiseConstructorLikeandConcatArray. - Add the
ThisType<T>marker interface. Flow does not give it TypeScript's contextualthisbehavior. - Numeric typed array callbacks accept
thisArg?: any, and their staticfrommethods accept mapping functions from any element type. - Libraries can redeclare
ReactDOM$UserVisibleStringto change the type accepted by user-visible React DOM string attributes such asaria-label,title,alt, andplaceholder. Boolean()accepts no argument.Object.definePropertyandObject.definePropertiesreturn their first argument's type.Object.getPrototypeOf,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getOwnPropertySymbols,Object.isSealed,Object.isFrozen, andObject.isExtensibleaccept any argument.Object.prototype.valueOfreturnsObjectinstead ofunknown.String.prototype.matchAllyieldsRegExpExecArrayfor string patterns as well as regular expressions.