diff --git a/cli/src/commands/runTests.js b/cli/src/commands/runTests.js index 929d728995..e8a3685d32 100644 --- a/cli/src/commands/runTests.js +++ b/cli/src/commands/runTests.js @@ -381,6 +381,7 @@ export async function writeFlowConfig( '[options]', 'include_warnings=true', 'server.max_workers=0', + semver.gte(version, '0.200.0') ? 'exact_by_default=true' : '', // from version 0.202.0 default is true // Fixes out of shared memory error for Mac Rosetta 2, see https://github.com/facebook/flow/issues/8538 'sharedmemory.heap_size=3221225472', semver.lt(version, '0.125.0') @@ -542,6 +543,7 @@ async function removeTrashFromBinDir() { const CONFIGURATION_CHANGE_VERSIONS = [ 'v0.104.0', // Adding lint 'v0.125.0', // Remove suppress_comments + 'v0.200.0', // exact_by_default become required ]; /** diff --git a/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/react-router-dom_v6.x.x.js b/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/react-router-dom_v6.x.x.js index c4f597ce4d..2550daaa72 100644 --- a/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/react-router-dom_v6.x.x.js +++ b/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/react-router-dom_v6.x.x.js @@ -24,13 +24,10 @@ declare module "react-router-dom" { declare export var NavLink: React$ComponentType<{ +to: string | LocationShape, - +activeClassName?: string, - +className?: string, - +activeStyle?: { +[string]: mixed, ... }, - +style?: { +[string]: mixed, ... }, - +isActive?: (match: Match, location: Location) => boolean, - +children?: React$Node, - +exact?: boolean, + +className?: string | (props: {| isActive: boolean, isPending: boolean |}) => string | void, + +style?: { +[string]: mixed, ... } | (props: {| isActive: boolean, isPending: boolean|}) => { +[string]: mixed, ... } | void, + +children?: React$Node | ({| isActive: boolean, isPending: boolean |}) => React$Node, + +end?: boolean, +strict?: boolean, ... }> @@ -441,7 +438,7 @@ declare module "react-router-dom" { declare export function useHistory(): $PropertyType; declare export function useLocation(): $PropertyType; - declare export function useOutletContext(): T; + declare export function useOutletContext(): T; declare export function useParams, 'params'>>(): Params; declare export function useRouteMatch(path?: MatchPathOptions | string | string[]): $PropertyType; @@ -464,28 +461,23 @@ declare module "react-router-dom" { declare export type RouteObject = IndexRouteObject | NonIndexRouteObject; - declare export function createRoutesFromChildren( - children: React$Node, - ): Array; + declare export function createRoutesFromElements(elements: React$Node): RouteObject[] + declare export var createRoutesFromChildren: typeof createRoutesFromElements; declare export type Params = { +[key: Key]: string | void; }; - declare type RouteMatch = {| - params: Params, - pathname: string, - route: RouteObject, - |}; + declare export type RouteMatch = AgnosticRouteMatch - declare export function matchRoutes( + declare export function matchRoutes( routes: Array, location: LocationShape | string, basename?: string, - ): Array> | null; + ): Array> | null; - declare export function renderMatches( - matches: Array> | null, + declare export function renderMatches( + matches: Array> | null, ): React$Element | null; declare type PathPattern = {| diff --git a/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/test_react-router-dom.js b/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/test_react-router-dom.js index e99567a96e..ca39ee3cc5 100644 --- a/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/test_react-router-dom.js +++ b/definitions/npm/react-router-dom_v6.x.x/flow_v0.104.x-/test_react-router-dom.js @@ -6,6 +6,8 @@ import { Link, NavLink, matchPath, + matchRoutes, + renderMatches, withRouter, Navigate, Outlet, @@ -14,12 +16,15 @@ import { useHistory, useLocation, useNavigate, + useOutlet, useOutletContext, useParams, useRouteMatch, useMatches, } from "react-router-dom"; import type { + AgnosticRouteMatch, + RouteObject, Location, ContextRouter, Match, @@ -121,13 +126,10 @@ describe("react-router-dom", () => { true} strict - exact + end > About ; @@ -163,6 +165,44 @@ describe("react-router-dom", () => { // $FlowExpectedError[incompatible-type] - to prop must be a string or LocationShape ; + + // activeClassName, activeStyle, end, isActive have been dropped unfortunately props cannot be strict so no errors can be expected + true} + end + > + About + ; + }); + + it('supports enhanced className & style props', () => { + + isPending ? "pending" : isActive ? "active" : undefined + } + style={({ isActive, isPending}) => + isPending ? { color: "red" } : isActive ? { color: "blue" } : undefined + } + > + About + ; + + // $FlowExpectedError[incompatible-type] + ; + // $FlowExpectedError[incompatible-type] + ; + }); + + it('supports render prop as children', () => { + + {({ isActive, isPending }) => ( + Tasks + )} + }); }); @@ -197,6 +237,58 @@ describe("react-router-dom", () => { }); }); + describe('renderMatches', () => { + it('works', () => { + renderMatches([]); + + renderMatches([]); + + const contentWithEmptyMatches: null|React$Element = renderMatches([]); + + const contentWithMatches: null|React$Element = renderMatches([{ + params: {}, + pathname: '/', + pathnameBase: '', + route: { + index: false, + children: [{ + index: true, + }], + }, + }]); + }); + + it('raises', () => { + // $FlowExpectedError[incompatible-call] + renderMatches(5); + + // $FlowExpectedError[incompatible-type] + const contentWithEmptyMatches: number = renderMatches([]); + }); + }); + + describe('matchRoutes', () => { + it('works', () => { + matchRoutes([], '/'); + + matchRoutes([], '/'); + + const contentWithEmptyMatches: Array> | null = matchRoutes([], '/'); + + const contentWithMatches: Array> | null = matchRoutes([{ + id: 'bar', + path: 'bar', + index: false, + children: [], + }], '/'); + }); + + it('raises an error with invalid arguments', () => { + // $FlowExpectedError[incompatible-call] + matchRoutes(5, '/'); + }); + }); + describe("withRouter", () => { type Props = { history: RouterHistory, @@ -496,12 +588,34 @@ describe("react-router-dom", () => { }); it('useOutlet', () => { + useOutlet() + + const Component = () =>
Hi!
; + + useOutlet() + + // $FlowExpectedError[extra-arg] + useOutlet('') + }) + + it('useOutletContext', () => { const [count, setCount] = useOutletContext(); const increment = () => setCount((c) => c + 1); ; // $FlowExpectedError[extra-arg] useOutletContext(''); + + const t1: number = useOutletContext(); + + type Tuple = [string, (foo: string) => void]; + + const [foo, setFoo] = useOutletContext(); + (foo: string); + (setFoo: (foo: string) => void); + + // $FlowExpectedError[incompatible-type] + const t2: string = useOutletContext(); }); it('useParams', () => {