Releases: facebook/flow
Releases · facebook/flow
v0.261.1
v0.261.0
New Features:
- Bigint values inside of template literals now coerce to strings, e.g.
`${1n}`
. Addition with string (e.g.1n + 'blah'
) is still banned. - Add ability to resolve node package entrypoints/exports
- Flow now allows inference of type guards for simple expression arrow functions with one parameter. For example, in
["a", null].filter(s => s != null)
it will automatically infer that the arrow function encodes ax is string
type guard and will apply it on the input array resulting in aArray<string>
. (try-Flow) module.system.node.root_relative_dirname
will allow conditional mapping likemodule.system.node.root_relative_dirname='<PROJECT_ROOT>/foo' -> 'bar'
. Under such config,import 'a'
will only be resolved to<PROJECT_ROOT>/bar/a
ifimport 'a'
is in a file in the<PROJECT_ROOT>/foo
directory. This feature will be helpful if you want to combine two flow roots with differentmodule.system.node.root_relative_dirname
config.
Likely to cause new Flow errors:
- When an opaque type is refined to be not null/undefined, we now refine the opaque type's upper bound rather than returning the opaque type unmodified.
Notable bug fixes:
- Flow will error more consistently on incompatible uses of refined string, number and boolean literal types (e.g. try-Flow)
- Fixed some cases of type filtering during type guard refinement (e.g. try-Flow)
- Fixed a bug of missing errors when certain functions were checked against interfaces (e.g. try-Flow)
- Fixed negation of refinement of type-guard functions with multiple parameters (e.g. try-Flow)
- Relaxed type-guard consistency checks when the function returns with
true
orfalse
. (e.g. try-Flow)
Parser:
- We now provide parsing support for
declare global {...}
(using it will still result in an error). The AST will have the shape of
{
"type":"DeclareNamespace",
"loc": ...,
"range": ...,
"global":true,
"id":{
"type":"Identifier",
"loc": ...,
"range":...,
"name":"global",
"typeAnnotation":null,
"optional":false
},
"body":{
"type":"BlockStatement",
...
},
}
Library Definitions:
- The global
React$PureComponent
is removed. If you want to refer to it, it needs to be imported fromreact
.
v0.260.0
New Features:
- You may now write object literals with Flow Enum values as computed keys. This will result in a dictionary type, keyed by the Flow Enum type. Note that all possible Flow Enum representation types are valid object keys, so we just support all of them.
- You can use
number
typed keys (rather than just number literals) to create objects, these will be treated as dictionaries{[number]: T}
Notable bug fixes:
- Fixed soundness hole in subtyping of type guard functions (e.g. try-Flow)
- Fixed a bug that caused spurious errors when type guards were used in private methods (e.g. try-Flow)
- Flow will no longer invalidate refinements made before the loop for const-like variables within a loop (example)
IDE:
- For identifiers of array patterns bind to a require call, go-to-definition will jump to itself.
Library Definitions:
- The internal type
React$FragmentType
is removed from Flow's builtin global type definitions.
v0.259.1
Notable bug fixes:
- Fixed a bug that causes experimental auto-import-on-paste to miss imports for component names used in jsx.
v0.259.0
Likely to cause new Flow errors:
- When a function without statics is passed to a place that expects inexact objects, the error will just say "function without statics is incompatible with object", instead of listing all the missing props in statics in errors. Error code might change.
- When a non-callable object is passed to a place expecting functions, we will have a clearer message saying "non-callable object is incompatible with function" instead of the current error talking about the callable property. Some error code might change, which requires new suppressions.
Notable bug fixes:
- For errors involving unions and intersections, we will now show a list of possible causes in a sorted order: the ones that are mostly likely to be the cause will be shown first.
IDE:
- We slightly changed the go-to-definition behavior for export from statements:
- For
bar
inexport {foo as bar} from '...'
, we will always jump to itself - For
foo
inexport {foo} from '...'
orexport {foo as bar} from '...'
, we will always jump to the name at the export, if this statement is well typed. - For
foo
inexport {foo} from '...'
orexport {foo as bar} from '...'
, we will jump to itself if the statement is not well-typed.
- For
- Go-to-definition on intrinsic jsx elements will jump to nowhere instead of jump to itself.
- Go-to-definition for
require('...')
expression will now jump to the default export of an ESM module if available, or the first export of an ESM module.
Library Definitions:
- Type for
React.Context
has been updated to support React 19's context as provider model. Given this change, you might need additional annotations on exports. e.g.
v0.258.1
IDE:
- Fixed go-to-definition for Meta-specific module references.
v0.258.0
Likely to cause new Flow errors:
- method-unbinding errors will not affect choice over intersection members. (e.g. try-Flow)
- We now disallow coercions between functions and class statics.
- The ability to configure
react.ref_as_prop=disabled
is removed. - Use of
React$Node
andReact$MixedElement
outside of libdefs will now triggerinternal-type
errors.
Library Definitions:
- Improved definition of
Array.concat()
.
v0.257.1
Misc:
- Flow language server will stop advertising that we can handle all code actions kinds prefixed with
"source"
. It can help to prevent VSCode sending flow irrelevant code actions to handle during save.
v0.257.0
Likely to cause new Flow errors:
- We have improved inference for exported primitive literal values.
- Before this change the inferred type for
export const obj = {f: "foo"};
was{f: str<"foo">}
, wherestr<"foo">
was a type that opportunistically and unsoundly behaved either asstring
or as the singleton type"foo"
. - Flow will now infer the type
{f: string}
forobj
. - For const like exports, e.g.
export const x = "foo";
Flow will export the type"foo"
. - To fix errors that arise due to this change, you can provide annotations around exported literals or use the
as const
modifier.
- Before this change the inferred type for
- We fixed a major unsoundness with regards to dictionary object creation. Previously, the computed property will just be ignored for
string
orany
keys. Now, if the computed property is added to some existing objects (e.g.{foo: string, [stringTypedKey]: v}
), then we will error on the property. Otherwise, the{[key]: value}
will be{[typeof key}: typeof value}
- We fixed a bug that causes opaque type's underlying representation to leak beyond the file it's defined. You might see more errors as a result.
- Flow will now perform a complete function call check even when
[react-rule-unsafe-mutation]
errors are raised. - Previously we incorrectly distribute-over-union for maybe or optional input types of conditional type. (e.g.
(?string) extends string ? true : false
is evaluated totrue | false
instead offalse
). This is now fixed, and code that depends on the bug might have new errors. - If you have refiend a value based on
typeof x === 'function'
, and then dotypeof x === 'object'
, the result is nowempty
as that is impossible. - Singleton types are now also considered in conditional equality checks on member expressions. (e.g. try-Flow)
React.Config
type, deprecated in v0.254, is now removed.
New Features:
'key' in x
now refines the type ofx
to objects which have the propertykey
.in
checks for both own and non-own properties.- If we find that a key does not exist in an inexact object or instance/interface, then the negation is not refined since the property may or may not exist.
- An optional property is also considered as if it may or may not exist.
- If a proto/super is a union, every member of the union must have it
- If the input to the refinement is an intersection, one member of that intersection must have it
- We don't refine arrays since it's not useful (check for
.length
instead), and also because Flow doesn't handle array holes.
- Flow now supports
no_unchecked_indexed_access=true
in flowconfig, which is equivalent to noUncheckedIndexedAccess from TS. It will add| void
to every indexed access with general string key on dictionary objects or number key on arrays. - Support for React 19's ref-as-prop model is now available via
react.ref_as_prop=partial_support
, and this is now the default. (To disable it, usereact.ref_as_prop=disabled
.) Under this mode, ref prop in jsx will be treated as a regular prop for function components, but utility types likeReact.ElementConfig<...>
still won't include the regular ref prop yet. - Flow now allows using union of strings as the type of computed property keys.
- You can now destructure object properties using number literal keys (which are int-like).
Notable bug fixes:
- Refining type guards with opaque types will now refine the general type (example of code that used to fail before, but now passes: try-Flow)
- Allow more flexibility in checks involving super type of opaque type (e.g. try-Flow)
- Fixed a bug when using opaque types in type guards in files other than the one where the type guard function was defined.
- We now allow a union of generic or opaque string typed values to be used as a key of computed property, if it's bounded by a string type.
Library Definitions:
- Add libdef types for
getNotifications
andshowNotification
API forServiceWorkerRegistration