github meta/flow v0.344.0

6 hours ago

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 TNext of a generator without a return annotation is inferred from what its yields are expected to be and from the iterables it delegates to, as in TypeScript, and a yield in such a generator is what it is expected to be, or unknown, rather than void
  • 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, Required and Readonly of an intersection now keep a read-only index signature
  • A refinement of a stuck evaluation, such as Partial<T> for a type parameter T, narrows its upper bound as it does for a type parameter, instead of giving empty.
  • Readonly, Partial, Required and homomorphic mapped types give back a primitive type unchanged, as in TypeScript; Readonly<null> and Readonly<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 module can use export * from, export * as ns from, export {...} from and export {...}.
  • A global block in a library declare module declares 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.C and export import X = A.B.C are now supported.
  • A class can now implement a class declared in TypeScript, as in TypeScript.
  • Mapped types, Readonly, Partial and 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 any and template literal types
  • An interface that extends the type of a class value can be constructed and extended like the class
  • An interface merged into a declare class adds the members of the interfaces it extends to the class, as in TypeScript
  • Flow no longer crashes on a namespace in a library declare module that extends one of the module's imports or uses an import() type.
  • A namespace with only types in a library declare module without 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 of X, also when it comes before the declaration of X.
  • A parameter of a function type is in scope in the types after it, so typeof can refer to it, as in TypeScript
  • Support computed [Symbol.*] and value-bound property keys in flow-api-translator, flow-transform, and flow-eslint, and stop emitting @@iterator in flowToFlowDef.
  • In TypeScript libraries and files, typeof C.x reads a member x of a namespace merged into the class C without going through the type of C, so an interface merged into C can 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 the Map and Set constructors 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 extends in the declaring file, as it already had in importing modules.
  • this in a generic inline interface, as in type 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 function can now be named as f.T.
  • Fixed slow checks of generic components whose props nest mapped types, such as Omit of Omit, and have defaultProps.
  • A TypeScript declare module without an export declaration now exports each of its declarations, even when some of them are declared with export.
  • 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 const or other value is no longer ignored.
  • instanceof refines 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 declare variable statement, so a const there 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, AsyncIterableIterator and AsyncIteratorObject are covariant in their yield and return types and contravariant in their next type, as their sync counterparts are.
  • IteratorResult, IteratorYieldResult and IteratorReturnResult are covariant, as in TypeScript.
  • RegExpStringIterator is covariant, as in TypeScript.
  • Add typings for stable React ViewTransition and cache APIs.
  • filter(Boolean) on iterators no longer removes null and undefined from the element type, as in TypeScript.
  • Load TypeScript's IteratorResult declaration verbatim
  • Intl.SegmentIterator is covariant, as in TypeScript.
  • Iterator can be subclassed, as in TypeScript
  • The iterator helpers' filter and find take TypeScript's two-sided type guards
  • Omit now uses TypeScript's key selection and no longer infers T.
  • Symbol.iterator and Symbol.asyncIterator are unique symbols, as in TypeScript, so a property keyed by the string '@@iterator' no longer makes an object iterable
  • Symbol.dispose and Symbol.asyncDispose are unique symbols, as in TypeScript
  • An interface can now extend Partial<T>, Required<T> and Readonly<T>.
  • Map, Set, WeakMap and WeakSet constructors and Promise.all/Promise.race take TypeScript's Iterable overloads

Don't miss a new flow release

NewReleases is sending notifications on new releases.