Skip to content

Releases: facebook/flow

v0.235.1

24 Apr 04:07
Compare
Choose a tag to compare

Likely to cause new Flow errors (copied from 0.235.0 release notes):

  • Flow's react-rule enforcement now detects reads from ref.current within nested functions of hooks and components that are called during rendering.
  • obj[key] where obj is not a dictionary object and key is a string used to not error and just silently return any. We now error on this pattern.

Misc:

  • By default, flow ast will now parse component syntax rather than reject it. You can pass --no-component-syntax to get the old behavior (D56501290 samzhou19815)

v0.234.0

17 Apr 20:49
Compare
Choose a tag to compare

Likely to cause new Flow errors:

  • Flow might catch more inexact incompatible with exact errors. example
  • Fixed a bug that leads to Flow sometimes ignoring differences in call props of an object. New errors might be exposed. example
  • We rewrite the way we generate types for annotations. We will now detect and error on trivially recursive types like type T = T or type Foo = typeof foo; const foo: Foo = .... In addition to this, you might see some errors being moved around.
  • Fixed Flow Enums exhaustive checking logic when input is a generic.
  • Invalid indexed access types with string index, like {foo: string}[string], will now error instead of silently making it any.

New Features:

  • You can have a tuple spread of a generic in the parameter of a function and not have to supply the relevant type argument if that spread is the only spread in that tuple, and it is the last element of that tuple.
  • Negative numbers are now allowed in Flow Enum values.
  • Allow Flow Enums to be cast to their representation type when the cast expression is typed as a generic type.
  • Added a new global type EnumValue<>, which represents all Flow Enum values. You can constrain the enum values to those with a particular representation type by supplying the type argument, e.g. EnumValue<string>.
  • Added a new global type Enum<>, which represents all Flow Enums (this is a complement to the new EnumValue type). You can constrain the enums to ones which have a particular enum value, e.g. Enum<> is the same as Enum<EnumValue<>>, and the type of all enums with string representation types is Enum<EnumValue<string>>. These "abstract enums" have no know members, so you can't access members or exhaustively check them, but you can use methods such as .members(), .cast(), etc.
  • Allow === comparison of abstract Flow Enums as well as Enums themselves with the same ID.
  • You can now cast Flow Enum values to their representation type using .valueOf(), e.g. enum E {A, B}; const s: string = E.A.valueOf().

Notable bug fixes:

  • We now error more reliably in the matching property tests, for example when the object part is a complex expression. example
  • Fixed spurious errors in propagating type hints. example
  • Infer type in a conditional type is now allowed to be underconstrained. When the true branch is taken, this underconstrained infer type will be pinned to the upper bound. example
  • Add Enum and EnumValue to $NotNullOrVoid - previously there was no supertype for all enum values or enums.

IDE:

  • We now show jsdoc information on component props with component syntax.

v0.233.0

03 Apr 16:01
Compare
Choose a tag to compare

Likely to cause new Flow errors:

  • Flow will now error on invalid type applications at the declaration site, if the type application does not use another generic type from an outer scope. example
  • We fixed a bug where we incorrectly unwrapped the opaque type to the underlying representation in refinements
  • Predicate functions (%checks) can no longer be recursive
  • Fixed subtyping of indexers in instances/interfaces

Notable bug fixes:

  • We fixed some spurious errors regarding opaque type refinements. example
  • We made a change to method-unbinding errors so that it no longer errors when in an any/mixed context. This allows us to better support jest
  • We fixed an issue where explicitly supplied JSX type arguments were ignored
  • We fixed bigint Flow Enums that do not explicitly speicy of bigint during parsing. We were previously not correctly inferring that this was a bigint enum.
  • flow.org/try now supports go-to-definition, autocomplete, and signature help

Parser:

  • Previously Flow outputs ReadOnlyTypeAnnotation in parser output for annotations like readonly string[]. Now we output it as TypeOperator with "operator": "readonly"

IDE:

  • Fix printer output of casting syntax when LHS of as or as const has low precedence

Library Definitions:

  • We migrated the built-in React library definitions to use component and hook syntax for various React-provided APIs. Look out for a blog post on our medium account for more details and see the React section in our docs

v0.232.0

26 Mar 19:38
Compare
Choose a tag to compare

Likely to cause new Flow errors:

  • Support for $Compose and $ComposeReverse types are removed. We recommend to use overloads to approximate their behavior instead. e.g.
declare export function compose(): <T>(a: T) => T;
declare export function compose<F: (...$ReadOnlyArray<empty>) => mixed>(
  f: F,
): F;
declare export function compose<A, T: $ReadOnlyArray<any>, R>(
  f1: (a: A) => R,
  f2: (...T) => A,
): (...T) => R;
declare export function compose<A, B, T: $ReadOnlyArray<any>, R>(
  f1: (b: B) => R,
  f2: (a: A) => B,
  f3: (...T) => A,
): (...T) => R;
declare export function compose<A, B, C, T: $ReadOnlyArray<any>, R>(
  f1: (c: C) => R,
  f2: (b: B) => C,
  f3: (a: A) => B,
  f4: (...T) => A,
): (...T) => R;
declare export function compose<R>(
  f1: (b: any) => R,
  ...funcs: $ReadOnlyArray<(...$ReadOnlyArray<empty>) => mixed>
): (...$ReadOnlyArray<any>) => R;
declare export function compose<R>(
  ...funcs: $ReadOnlyArray<(...$ReadOnlyArray<empty>) => mixed>
): (...$ReadOnlyArray<any>) => R;
  • You might see more errors around type application. example
  • Fix subtyping of indexers in instances/interfaces. example

New Features:

  • Updated the isValid Flow Enums method to use a type guard, allowing it to refine its input to the enum type in a conditional context.
    E.g.
enum Status {Active, Off}
const s = "Active";
if (Status.isValid(s)) {
  s as Status; // Should work
}
  • export type Foo = ... and export interface Bar {...} statements are now allowed in declare module and declare namespace bodies.
  • We added a new codemod flow codemod remove-unnecessary-react-import which can help remove unnecessary react imports under react.runtime=automatic

Notable bug fixes:

  • Fixed issue when explicitly supplied JSX type arguments are ignored
  • Fixed code action output of casting syntax when LHS of as or as const has low precedence

Library Definitions:

  • Added definitions for the following APIs:
    • window.showOpenFilePicker(): MDN, WICG
    • window.showSaveFilePicker(): MDN, WICG
    • window.showDirectoryPicker(): MDN, WICG
    • DataTransferItem.getAsFileSystemHandle(): MDN, WICG
    • StorageManager.getDirectory(): MDN, WHATWG

v0.231.0

13 Mar 22:45
Compare
Choose a tag to compare

Likely to cause new Flow errors:

  • Fixed subtyping of inline interfaces, e.g. try-flow.

New Features:

  • No longer trigger method-unbinding errors with indexed access types.
  • Add relay_integration.esmodules option. When this option, along with relay_integration, is enabled, Flow will treat graphql fragments/queries/etc. as import default rather than require. Use this when you ouput ESM from Relay's codegen (e.g. eagerEsModules).

Notable bug fixes:

  • Don't error when returning an array, map, etc when an AsyncGenerator<T, void, void> type is expected (e.g. try-Flow)

IDE:

  • Fixed a bug where AUTO332 appeared in the result of string literal type completion.

Library Definitions:

  • Added definitions for FileSystem APIs (thanks @ZelJin).
  • Added constructor to the StorageManager class (thanks @ZelJin).
  • Removed checkPropTypes, DOM, createClass, ConcurrentMode from react module.
  • Types in react module can now also be used when React is default imported like import React from 'react', they can also be used without imports, e.g. type N = React.Node.

v0.230.0

06 Mar 02:10
Compare
Choose a tag to compare

Likely to cause new Flow errors:

  • We now put value exports and type exports into two different namespaces. It means that we will now consistently error on places where you try to import, re-export, or use a imported type as a value. This change also makes certain patterns that happen to work in the past no longer work, e.g.
// a.js
export type Foo = string;
// b.js
const A = require('./a');
module.exports = {...A};
// c.js
// previously allowed, no longer allowed
import type {Foo} from './b';
  • We have allowed function parameters to refer to each other for a while now. However, we didn't implement the analysis correctly for exported functions, which causes inconsistent behaviors. This is now fixed e.g.
// a.js
// we incorrectly resolve x to refer to
// be external to the function params,
// which is a global in this case
export function foo(x: string, y: typeof x) {}
// b.js
import {foo} from './a';
foo("", 3); // no error before, errors now
  • Previously, we allowed assignment to any globals, regardless of whether it's a type or value. Therefore, both were allowed in Array = 3; $ReadOnlyArray = 2; Now the latter is banned.
  • Flow now consistently bans referring a type-only global as value
  • Some bad annotations that cause value-as-type or recursive-definition errors will no longer affect which branch to take in overload resolution.

New Features:

  • Flow now supports typeof with type arguments type T = typeof foo<string>. This syntax is supported in prettier since v3.1. If you previously enabled the flag typeof_with_type_arguments=true, you need to remove it.
  • Flow now supports explicit type arguments on JSX. e.g. <Foo<string, _, number >propA='d' />. Note that some type arguments can be inferred using the _ syntax.
  • Flow now supports the same NoInfer intrinsic that will be available in TypeScript 5.4.
  • Under experimental.ts_syntax=true, Flow will
    • Automatically translate TypeScript's readonly on tuple and array types into Flow equivalent $ReadOnly<[...]> and $ReadOnlyArray<...> without error.
    • Automatically translate TypeScript's keyof into Flow equivalent $Keys without error. Note that there are behavior differences between $Keys<> and keyof right now (flow, TS), so use it with caution.
    • Automatically translate TypeScript's unknown never and undefined into Flow equivalent mixed empty and void without error.
    • Support TypeScript's variance annotation readonly in out, in out without error.

Misc:

v0.229.2

25 Feb 00:32
Compare
Choose a tag to compare

Misc:

  • Fixed a potential crash under the experimental flag experimental.blocking_worker_communication=false.

v0.229.1

21 Feb 04:33
Compare
Choose a tag to compare

Misc:

  • Bug fixes in preparation of new feature rollout

v0.229.0

15 Feb 01:10
Compare
Choose a tag to compare

Likely to cause new Flow errors:

  • invalid-recursive-exported-annotation will now have error code of recursive-definition.
  • Previously we would emit confusing errors when you try to use a value that has union types as a type. Now it will consistently emit value-as-type errors. (example).
  • Unsupported statements like loops within declare module will no longer cause parse errors. Instead, they will be errored on during type checking.
  • declare export type and declare export interface statements in toplevel are no longer parser errors. Instead, they will now be errored during type checking.
  • Previous toplevel-library-import errors and unsupported-statement-in-lib errors will all have unsupported-syntax error code now.

New Features:

  • We introduced experimental.ts_syntax flag that you can set to true. When this flag is on, Flow will no longer complain about certain TypeScript syntax, and will automatically turn them into the closest Flow equivalent types. Initially, we support the following: Readonly, ReadonlyArray, ReadonlyMap, ReadonlySet, NonNullable, and using extends to specify type parameter bounds. In the future, more kinds of types that we currently parse but error on might be added. (e.g. keyof). Please note that the support here is best effort. We make no guarantee that these types have the same semantics as those in TypeScript 100% of the time, but for common cases, it might be good enough for you.

Notable bug fixes:

  • We now allow the use of saved state for glean indexer, if saved state is enabled in flowoconfig or CLI arguments.
  • Improved the way we compute contextual hints for spread arguments of calls (e.g. try-Flow).
  • In declare module, all the values will be auto-exported if we cannot decide whether the module is in CJS or ESM. However, support for declare const and declare let was missing. This has now been fixed.

Misc:

  • Make both the default value for the .flowconfig casting_syntax option, if not supplied.

v0.228.0

01 Feb 23:31
Compare
Choose a tag to compare

Likely to cause new Flow errors:

  • Some new errors might be raised when using React.cloneElement with polymorphic components. Eg. try-Flow. Note that React.cloneElement is deprecated
  • Nested declare module is no longer a parser error, but a type checking error
  • declare module is now explicitly banned in nested scope and outside of library definition files. It already does nothing under those contexts.

New Features:

  • All kinds of imports are now supported in library definition files
  • We will no longer require annotations on class properties, if the class properties are already initialized with "annotation-like" expressions. e.g. We can now infer the type directly for properties like prop = (foo: string): number => 3.

Notable bug fixes:

  • Fixed a bug that causes the first run of flow check to always return 0 errors, when some parts of temporary directory is a symlink.
  • Hover type on react elements now show the type of the component and props, instead of just React$Element. (e.g. try-Flow)
  • For missing annotation on exports, we now correctly say some annotation is missing on an identifier instead of array pattern. e.g. for export function f(a) {}, we now say "Missing type annotation at identifier" instead of "Missing type annotation at array pattern".

Parser:

  • Flow can now parse declare namespace Foo {...} statements. The body of the declare namespace statement shares the same restrictions of declare module.
  • Invalid exports in declare module are no longer parse errors. They are now type checker errors.