Likely to cause new Flow errors:
- A distributive conditional type distributes over a type parameter bound that evaluates to a union
- Infer the type parameters of conditional types by the rules of the type arguments of calls.
- The
TNextof a generator without a return annotation is inferred from what itsyields are expected to be and from the iterables it delegates to, as in TypeScript, and ayieldin such a generator is what it is expected to be, orunknown, rather thanvoid - An opaque type without a supertype is refined like a type parameter without a bound, so refinements of it are checked instead of giving
empty. Partial,RequiredandReadonlyof an intersection now keep a read-only index signature- A refinement of a stuck evaluation, such as
Partial<T>for a type parameterT, narrows its upper bound as it does for a type parameter, instead of givingempty. Readonly,Partial,Requiredand homomorphic mapped types give back a primitive type unchanged, as in TypeScript;Readonly<null>andReadonly<void>are no longer{}.
New Features:
- A type parameter's bound may refer to the parameter, e.g.
T extends Comparable<T> - Allow callable interfaces as React components.
- A type guard inferred from a function body is two-sided when the function returning false rules out the guarded type, as in TypeScript
- A library
declare modulecan useexport * from,export * as ns from,export {...} fromandexport {...}. - A
globalblock in a librarydeclare moduledeclares globals, like TypeScript. - Like TypeScript, the declarations of an interface can leave out trailing type parameters that have defaults.
- TypeScript import aliases
import X = A.B.Candexport import X = A.B.Care now supported. - A class can now implement a class declared in TypeScript, as in TypeScript.
- Mapped types,
Readonly,Partialand spreads of a function type declared in TypeScript now operate on the function's statics, as in TypeScript. - In a TypeScript library definition, namespaces of the same name merge.
Notable bug fixes:
- A callback prop of a union or intersection of components that includes a generic component is now contextually typed from the props it is passed with.
- Conditional types and React utilities over a polymorphic function or component no longer fail when a type parameter's bound mentions an earlier type parameter.
- Functions with a rest parameter are accepted as React function components; their props are the first element of the rest parameter.
- A conditional type whose check type is an intersection now checks the whole intersection, not only its first member.
- Spreading a union of optional values no longer takes exponential time
- Preserve comments when using
flow-parser/babel-plugin. - Infer the type parameters in the other operands of a spread that bounds a type parameter
- Infer type arguments by the subtyping rules of classes, applications of
anyand template literal types - An interface that extends the type of a class value can be constructed and extended like the class
- An
interfacemerged into adeclare classadds the members of the interfaces it extends to the class, as in TypeScript - Flow no longer crashes on a namespace in a library
declare modulethat extends one of the module's imports or uses animport()type. - A namespace with only types in a library
declare modulewithout explicit exports is now exported. - A generic call in a conditional or logical expression no longer takes a type argument outside the type parameter's bound from the other operand.
- In TypeScript files, a type name no longer resolves to a value of the same name, as in TypeScript
- A TypeScript import of a name that a module exports as both a type and a value is the type in a type position.
- In TypeScript files and TypeScript library definitions,
export { X }exports every meaning ofX, also when it comes before the declaration ofX. - A parameter of a function type is in scope in the types after it, so
typeofcan refer to it, as in TypeScript - Support computed
[Symbol.*]and value-bound property keys inflow-api-translator,flow-transform, andflow-eslint, and stop emitting@@iteratorinflowToFlowDef. - In TypeScript libraries and files,
typeof C.xreads a memberxof a namespace merged into the classCwithout going through the type ofC, so an interface merged intoCcan use it as a computed key. - In TypeScript declarations, an exported namespace now merges into an exported function or class of the same name in the declaration itself, as it already did for importers.
- A TypeScript method whose rest param is a union of tuples, such as
next(...[value]: [] | [T]), now accepts a method with matching optional params. - An interface that extends a generic class or interface without type arguments can now redeclare a method that returns
this. - Fixed spurious errors on nested generic calls in the arguments of an overloaded function, such as
new Map([['k', new Set(['a'])]])when theMapandSetconstructors are overloaded. - An interface that extends a global class or interface, or a member of a global namespace, can now redeclare a method that returns
this. - A declared class merged with an interface now has the interface's
extendsin the declaring file, as it already had in importing modules. thisin a generic inline interface, as intype B<T> = interface {set(v: T): this}, now stands for the interface with its type arguments.- Applications of an alias of a constructor type or an inline interface that are compared by their expansions are now compared by their members.
- A type in a namespace merged into an overloaded
declare functioncan now be named asf.T. - Fixed slow checks of generic components whose props nest mapped types, such as
OmitofOmit, and havedefaultProps. - A TypeScript
declare modulewithout an export declaration now exports each of its declarations, even when some of them are declared withexport. - A class that extends a generic class imported from an
export =module through a namespace merged with the class now gets the type parameters' defaults. - A TypeScript namespace with only types that shares its name with a
constor other value is no longer ignored. instanceofrefines by each polymorphic overload of an overloaded construct signature- Applications of a TypeScript type alias that isn't covariant in its type parameters, like Lexical's
Spread, are now compared by their expansions, as in TypeScript.
Misc:
- Faster property lookups and subtyping checks through interfaces that extend several interfaces with common bases.
- Faster checking of code that uses generic types, classes and interfaces.
Parser:
- A class in a TypeScript ambient context is parsed as a
declare class, so it can be used before its declaration and merges with interfaces of the same name. - A variable statement without initializers in a TypeScript ambient context is parsed as a
declarevariable statement, so aconstthere has its declared type and merges into a namespace.
IDE:
- Go-to-definition on a merged namespace value goes to a declaration that declares values, not to one that declares only types.
Library Definitions:
AsyncIterator,AsyncIterable,AsyncIterableIteratorandAsyncIteratorObjectare covariant in their yield and return types and contravariant in their next type, as their sync counterparts are.IteratorResult,IteratorYieldResultandIteratorReturnResultare covariant, as in TypeScript.RegExpStringIteratoris covariant, as in TypeScript.- Add typings for stable React ViewTransition and cache APIs.
filter(Boolean)on iterators no longer removesnullandundefinedfrom the element type, as in TypeScript.- Load TypeScript's
IteratorResultdeclaration verbatim Intl.SegmentIteratoris covariant, as in TypeScript.Iteratorcan be subclassed, as in TypeScript- The iterator helpers'
filterandfindtake TypeScript's two-sided type guards Omitnow uses TypeScript's key selection and no longer infersT.Symbol.iteratorandSymbol.asyncIteratorareunique symbols, as in TypeScript, so a property keyed by the string'@@iterator'no longer makes an object iterableSymbol.disposeandSymbol.asyncDisposeareunique symbols, as in TypeScript- An interface can now extend
Partial<T>,Required<T>andReadonly<T>. Map,Set,WeakMapandWeakSetconstructors andPromise.all/Promise.racetake TypeScript'sIterableoverloads