Update Flow to 0.84 (#17805)

* Update Flow to 0.84

* Fix violations

* Use inexact object syntax in files from fbsource

* Fix warning extraction to use a modern parser

* Codemod inexact objects to new syntax

* Tighten types that can be exact

* Revert unintentional formatting changes from codemod
This commit is contained in:
Dan Abramov 2020-01-09 14:50:44 +00:00 committed by GitHub
parent b979db4e72
commit e706721490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
97 changed files with 313 additions and 233 deletions

View File

@ -8,6 +8,7 @@
"@babel/code-frame": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/helper-module-imports": "^7.0.0",
"@babel/parser": "^7.0.0",
"@babel/plugin-external-helpers": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
@ -36,7 +37,6 @@
"art": "^0.10.1",
"babel-eslint": "^10.0.0",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
"babylon": "6.18.0",
"chalk": "^1.1.3",
"cli-table": "^0.3.1",
"coffee-script": "^1.8.0",
@ -56,7 +56,7 @@
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
"fbjs-scripts": "^0.8.3",
"filesize": "^3.5.6",
"flow-bin": "^0.72.0",
"flow-bin": "^0.84.0",
"glob": "^6.0.4",
"glob-stream": "^6.1.0",
"google-closure-compiler": "20190301.0.0",

View File

@ -29,10 +29,10 @@ export function createSubscription<Property, Value>(
callback: (value: Value | void) => void,
) => Unsubscribe,
|}>,
): React$ComponentType<{
): React$ComponentType<{|
children: (value: Value | void) => React$Node,
source: Property,
}> {
|}> {
const {getCurrentValue, subscribe} = config;
if (__DEV__) {
@ -44,14 +44,14 @@ export function createSubscription<Property, Value>(
}
}
type Props = {
type Props = {|
children: (value: Value) => React$Element<any>,
source: Property,
};
type State = {
|};
type State = {|
source: Property,
value: Value | void,
};
|};
// Reference: https://gist.github.com/bvaughn/d569177d70b50b58bff69c3c4a5353f3
class Subscription extends React.Component<Props, State> {

View File

@ -16,7 +16,7 @@ import type {
import invariant from 'shared/invariant';
type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>};
type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>, ...};
type EventPluginOrder = null | Array<PluginName>;
/**

View File

@ -15,7 +15,7 @@ import type {
import type {TopLevelType} from './TopLevelEventTypes';
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
export type EventTypes = {[key: string]: DispatchConfig};
export type EventTypes = {[key: string]: DispatchConfig, ...};
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
@ -31,4 +31,5 @@ export type PluginModule<NativeEvent> = {
eventSystemFlags: EventSystemFlags,
) => ?ReactSyntheticEvent,
tapMoveThreshold?: number,
...
};

View File

@ -12,17 +12,17 @@ import type {Fiber} from 'react-reconciler/src/ReactFiber';
import type {EventPriority} from 'shared/ReactTypes';
import type {TopLevelType} from './TopLevelEventTypes';
export type DispatchConfig = {
export type DispatchConfig = {|
dependencies: Array<TopLevelType>,
phasedRegistrationNames?: {
phasedRegistrationNames?: {|
bubbled: string,
captured: string,
},
|},
registrationName?: string,
eventPriority: EventPriority,
};
|};
export type ReactSyntheticEvent = {
export type ReactSyntheticEvent = {|
dispatchConfig: DispatchConfig,
getPooled: (
dispatchConfig: DispatchConfig,
@ -31,4 +31,4 @@ export type ReactSyntheticEvent = {
nativeEventTarget: EventTarget,
) => ReactSyntheticEvent,
isPersistent: () => boolean,
} & SyntheticEvent<>;
|} & SyntheticEvent<>;

View File

@ -16,7 +16,7 @@ import {isStartish, isMoveish, isEndish} from './ResponderTopLevelEventTypes';
* should typically only see IDs in the range of 1-20 because IDs get recycled
* when touches end and start again.
*/
type TouchRecord = {
type TouchRecord = {|
touchActive: boolean,
startPageX: number,
startPageY: number,
@ -27,7 +27,7 @@ type TouchRecord = {
previousPageX: number,
previousPageY: number,
previousTimeStamp: number,
};
|};
const MAX_TOUCH_BANK = 20;
const touchBank: Array<TouchRecord> = [];
@ -46,10 +46,12 @@ type Touch = {
pageX: number,
pageY: number,
timestamp: number,
...
};
type TouchEvent = {
changedTouches: Array<Touch>,
touches: Array<Touch>,
...
};
function timestampForTouch(touch: Touch): number {

View File

@ -13,11 +13,10 @@ import {createLRU} from './LRU';
type Thenable<T> = {
then(resolve: (T) => mixed, reject: (mixed) => mixed): mixed,
...
};
type Suspender = {
then(resolve: () => mixed, reject: () => mixed): mixed,
};
type Suspender = {then(resolve: () => mixed, reject: () => mixed): mixed, ...};
type PendingResult = {|
status: 0,
@ -39,6 +38,7 @@ type Result<V> = PendingResult | ResolvedResult<V> | RejectedResult;
type Resource<I, V> = {
read(I): V,
preload(I): void,
...
};
const Pending = 0;

View File

@ -36,6 +36,7 @@ type HookLogEntry = {
primitive: string,
stackError: Error,
value: mixed,
...
};
let hookLog: Array<HookLogEntry> = [];
@ -142,7 +143,7 @@ function useReducer<S, I, A>(
return [state, (action: A) => {}];
}
function useRef<T>(initialValue: T): {current: T} {
function useRef<T>(initialValue: T): {|current: T|} {
let hook = nextHook();
let ref = hook !== null ? hook.memoizedState : {current: initialValue};
hookLog.push({
@ -174,7 +175,7 @@ function useEffect(
}
function useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
inputs: Array<mixed> | void | null,
): void {
@ -285,6 +286,7 @@ export type HooksNode = {
name: string,
value: mixed,
subHooks: Array<HooksNode>,
...
};
export type HooksTree = Array<HooksNode>;

View File

@ -27,6 +27,7 @@ type ConnectOptions = {
resolveRNStyle?: ResolveNativeStyle,
isAppActive?: () => boolean,
websocket?: ?WebSocket,
...
};
installHook(window);
@ -120,7 +121,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
});
bridge.addListener(
'inspectElement',
({id, rendererID}: {id: number, rendererID: number}) => {
({id, rendererID}: {id: number, rendererID: number, ...}) => {
const renderer = agent.rendererInterfaces[rendererID];
if (renderer != null) {
// Send event for RN to highlight.

View File

@ -109,7 +109,7 @@ export default class Agent extends EventEmitter<{|
_bridge: BackendBridge;
_isProfiling: boolean = false;
_recordChangeDescriptions: boolean = false;
_rendererInterfaces: {[key: RendererID]: RendererInterface} = {};
_rendererInterfaces: {[key: RendererID]: RendererInterface, ...} = {};
_persistedSelection: PersistedSelection | null = null;
_persistedSelectionMatch: PathMatch | null = null;
_traceUpdatesEnabled: boolean = false;
@ -185,7 +185,7 @@ export default class Agent extends EventEmitter<{|
setupTraceUpdates(this);
}
get rendererInterfaces(): {[key: RendererID]: RendererInterface} {
get rendererInterfaces(): {[key: RendererID]: RendererInterface, ...} {
return this._rendererInterfaces;
}

View File

@ -30,6 +30,7 @@ export function initBackend(
id: number,
renderer: ReactRenderer,
rendererInterface: RendererInterface,
...
}) => {
agent.setRendererInterface(id, rendererInterface);
@ -91,7 +92,7 @@ export function initBackend(
subs.push(
hook.sub(
'renderer',
({id, renderer}: {id: number, renderer: ReactRenderer}) => {
({id, renderer}: {id: number, renderer: ReactRenderer, ...}) => {
attachRenderer(id, renderer);
},
),

View File

@ -19,7 +19,7 @@ export function decorate(object: Object, attr: string, fn: Function): Function {
export function decorateMany(
source: Object,
fns: {[attr: string]: Function},
fns: {[attr: string]: Function, ...},
): Object {
const olds = {};
for (const name in fns) {

View File

@ -76,7 +76,7 @@ import type {
type getDisplayNameForFiberType = (fiber: Fiber) => string | null;
type getTypeSymbolType = (type: any) => Symbol | number;
type ReactSymbolsType = {
type ReactSymbolsType = {|
CONCURRENT_MODE_NUMBER: number,
CONCURRENT_MODE_SYMBOL_STRING: string,
DEPRECATED_ASYNC_MODE_SYMBOL_STRING: string,
@ -94,7 +94,7 @@ type ReactSymbolsType = {
STRICT_MODE_SYMBOL_STRING: string,
SCOPE_NUMBER: number,
SCOPE_SYMBOL_STRING: string,
};
|};
type ReactPriorityLevelsType = {|
ImmediatePriority: number,

View File

@ -48,13 +48,13 @@ export type FindNativeNodesForFiberID = (id: number) => ?Array<NativeType>;
export type ReactProviderType<T> = {
$$typeof: Symbol | number,
_context: ReactContext<T>,
...
};
export type ReactRenderer = {
findFiberByHostInstance: (hostInstance: NativeType) => ?Fiber,
version: string,
bundleType: BundleType,
// 16.9+
overrideHookState?: ?(
fiber: Object,
@ -62,30 +62,25 @@ export type ReactRenderer = {
path: Array<string | number>,
value: any,
) => void,
// 16.7+
overrideProps?: ?(
fiber: Object,
path: Array<string | number>,
value: any,
) => void,
// 16.9+
scheduleUpdate?: ?(fiber: Object) => void,
setSuspenseHandler?: ?(shouldSuspend: (fiber: Object) => boolean) => void,
// Only injected by React v16.8+ in order to support hooks inspection.
currentDispatcherRef?: {|current: null | Dispatcher|},
// Only injected by React v16.9+ in DEV mode.
// Enables DevTools to append owners-only component stack to error messages.
getCurrentFiber?: () => Fiber | null,
// Uniquely identifies React DOM v15.
ComponentTree?: any,
// Present for React DOM v12 (possibly earlier) through v15.
Mount?: any,
...
};
export type ChangeDescription = {|
@ -267,12 +262,13 @@ export type RendererInterface = {
count: number,
) => void,
updateComponentFilters: (componentFilters: Array<ComponentFilter>) => void,
...
};
export type Handler = (data: any) => void;
export type DevToolsHook = {
listeners: {[key: string]: Array<Handler>},
listeners: {[key: string]: Array<Handler>, ...},
rendererInterfaces: Map<RendererID, RendererInterface>,
renderers: Map<RendererID, ReactRenderer>,
@ -299,4 +295,5 @@ export type DevToolsHook = {
// Added in v16.9 to support Fast Refresh
didError?: boolean,
) => void,
...
};

View File

@ -95,6 +95,7 @@ export default function setupHighlighter(
openNativeElementsPanel: boolean,
rendererID: number,
scrollIntoView: boolean,
...
}) {
const renderer = agent.rendererInterfaces[rendererID];
if (renderer == null) {

View File

@ -14,6 +14,7 @@ export type Rect = {
right: number,
top: number,
width: number,
...
};
// Get the window object for the document that a node belongs to,

View File

@ -21,11 +21,10 @@ import React, {createContext} from 'react';
export type Thenable<T> = {
then(resolve: (T) => mixed, reject: (mixed) => mixed): mixed,
...
};
type Suspender = {
then(resolve: () => mixed, reject: () => mixed): mixed,
};
type Suspender = {then(resolve: () => mixed, reject: () => mixed): mixed, ...};
type PendingResult = {|
status: 0,
@ -50,6 +49,7 @@ export type Resource<Input, Key, Value> = {
read(Input): Value,
preload(Input): void,
write(Key, Value): void,
...
};
const Pending = 0;
@ -73,9 +73,7 @@ function readContext(Context, observedBits) {
const CacheContext = createContext(null);
type Config = {
useWeakMap?: boolean,
};
type Config = {useWeakMap?: boolean, ...};
const entries: Map<
Resource<any, any, any>,

View File

@ -17,6 +17,7 @@ type Props = {
children: React$Node,
className?: string,
title?: string,
...
};
export default function Button({

View File

@ -24,6 +24,7 @@ type Props = {
data: ItemData,
index: number,
style: Object,
...
};
export default function ElementView({data, index, style}: Props) {

View File

@ -15,6 +15,7 @@ type Props = {
onFocus?: (event: FocusEvent) => void,
placeholder?: string,
value: any,
...
};
export default function AutoSizeInput({

View File

@ -199,6 +199,7 @@ type ElementsDropdownProps = {
owners: Array<Owner>,
selectedIndex: number,
selectOwner: SelectOwner,
...
};
function ElementsDropdown({
owners,
@ -245,6 +246,7 @@ type ElementViewProps = {
isSelected: boolean,
owner: Owner,
selectOwner: SelectOwner,
...
};
function ElementView({isSelected, owner, selectOwner}: ElementViewProps) {
const store = useContext(StoreContext);

View File

@ -38,7 +38,7 @@ const DEFAULT_INDENTATION_SIZE = 12;
export type ItemData = {|
numElements: number,
isNavigatingWithKeyboard: boolean,
lastScrolledIDRef: {current: number | null},
lastScrolledIDRef: {current: number | null, ...},
onElementMouseEnter: (id: number) => void,
treeFocused: boolean,
|};

View File

@ -99,6 +99,6 @@ export type DehydratedData = {|
| Unserializable
| Array<Dehydrated>
| Array<Unserializable>
| {[key: string]: string | Dehydrated | Unserializable},
| {[key: string]: string | Dehydrated | Unserializable, ...},
unserializable: Array<Array<string | number>>,
|};

View File

@ -20,6 +20,7 @@ type Props = {
data: ItemData,
index: number,
style: Object,
...
};
function CommitFlamegraphListItem({data, index, style}: Props) {

View File

@ -20,6 +20,7 @@ type Props = {
data: ItemData,
index: number,
style: Object,
...
};
function CommitRankedListItem({data, index, style}: Props) {

View File

@ -19,6 +19,7 @@ type Props = {
data: ItemData,
index: number,
style: Object,
...
};
function InteractionListItem({data: itemData, index, style}: Props) {

View File

@ -19,6 +19,7 @@ type Props = {
data: ItemData,
index: number,
style: Object,
...
};
function SnapshotCommitListItem({data: itemData, index, style}: Props) {

View File

@ -15,6 +15,7 @@ export type Theme = 'auto' | 'light' | 'dark';
type Context = {
isModalShowing: boolean,
setIsModalShowing: (value: boolean) => void,
...
};
const SettingsModalContext = createContext<Context>(((null: any): Context));

View File

@ -20,6 +20,7 @@ type Props = {
isDisabled?: boolean,
onChange: (isChecked: boolean) => void,
title?: string,
...
};
export default function Toggle({

View File

@ -106,7 +106,7 @@ export function useEditableValue(
}
export function useIsOverflowing(
containerRef: {current: HTMLDivElement | null},
containerRef: {current: HTMLDivElement | null, ...},
totalChildWidth: number,
): boolean {
const [isOverflowing, setIsOverflowing] = useState<boolean>(false);
@ -195,7 +195,7 @@ export function useLocalStorage<T>(
}
export function useModalDismissSignal(
modalRef: {current: HTMLDivElement | null},
modalRef: {current: HTMLDivElement | null, ...},
dismissCallback: () => void,
dismissOnClickOutside?: boolean = true,
): void {

View File

@ -11,9 +11,7 @@ import React from 'react';
import {createPortal} from 'react-dom';
import ErrorBoundary from './ErrorBoundary';
export type Props = {
portalContainer?: Element,
};
export type Props = {portalContainer?: Element, ...};
export default function portaledContent(
Component: React$StatelessFunctionalComponent<any>,

View File

@ -52,6 +52,7 @@ export type Unserializable = {
size?: number,
type: string,
unserializable: boolean,
...
};
// This threshold determines the depth at which the bridge "dehydrates" nested data.
@ -129,7 +130,7 @@ export function dehydrate(
| Unserializable
| Array<Dehydrated>
| Array<Unserializable>
| {[key: string]: string | Dehydrated | Unserializable} {
| {[key: string]: string | Dehydrated | Unserializable, ...} {
const type = getDataType(data);
let isPathWhitelistedCheck;
@ -375,7 +376,7 @@ export function hydrate(
parent[last] = undefined;
} else {
// Replace the string keys with Symbols so they're non-enumerable.
const replaced: {[key: Symbol]: boolean | string} = {};
const replaced: {[key: Symbol]: boolean | string, ...} = {};
replaced[meta.inspectable] = !!value.inspectable;
replaced[meta.inspected] = false;
replaced[meta.name] = value.name;

View File

@ -106,12 +106,8 @@ setBatchingImplementation(
);
export type DOMContainer =
| (Element & {
_reactRootContainer: ?RootType,
})
| (Document & {
_reactRootContainer: ?RootType,
});
| (Element & {_reactRootContainer: ?RootType, ...})
| (Document & {_reactRootContainer: ?RootType, ...});
function createPortal(
children: ReactNodeList,

View File

@ -65,13 +65,12 @@ export type Props = {
hidden?: boolean,
suppressHydrationWarning?: boolean,
dangerouslySetInnerHTML?: mixed,
style?: {
display?: string,
},
style?: {display?: string, ...},
bottom?: null | number,
left?: null | number,
right?: null | number,
top?: null | number,
...
};
export type EventTargetChildElement = {
type: string,
@ -83,18 +82,22 @@ export type EventTargetChildElement = {
left?: string,
right?: string,
top?: string,
...
},
...
},
...
};
export type Container = Element | Document;
export type Instance = Element;
export type TextInstance = Text;
export type SuspenseInstance = Comment & {_reactRetry?: () => void};
export type SuspenseInstance = Comment & {_reactRetry?: () => void, ...};
export type HydratableInstance = Instance | TextInstance | SuspenseInstance;
export type PublicInstance = Element | Text;
type HostContextDev = {
namespace: string,
ancestorInfo: mixed,
...
};
type HostContextProd = string;
export type HostContext = HostContextDev | HostContextProd;

View File

@ -25,7 +25,9 @@ type InputWithWrapperState = HTMLInputElement & {
initialValue: ToStringValue,
initialChecked: ?boolean,
controlled?: boolean,
...
},
...
};
let didWarnValueDefaultValue = false;
@ -178,10 +180,10 @@ export function updateWrapper(element: Element, props: Object) {
// eslint-disable-next-line
node.value != (value: any)
) {
node.value = toString(value);
node.value = toString((value: any));
}
} else if (node.value !== toString(value)) {
node.value = toString(value);
} else if (node.value !== toString((value: any))) {
node.value = toString((value: any));
}
} else if (type === 'submit' || type === 'reset') {
// Submit/reset inputs need the attribute removed completely to avoid

View File

@ -17,8 +17,8 @@ import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot';
export type RootType = {
render(children: ReactNodeList, callback: ?() => mixed): void,
unmount(callback: ?() => mixed): void,
_internalRoot: FiberRoot,
...
};
export type RootOptions = {
@ -26,7 +26,9 @@ export type RootOptions = {
hydrationOptions?: {
onHydrated?: (suspenseNode: Comment) => void,
onDeleted?: (suspenseNode: Comment) => void,
...
},
...
};
import {

View File

@ -19,11 +19,9 @@ if (__DEV__) {
didWarnValueDefaultValue = false;
}
type SelectWithWrapperState = HTMLSelectElement & {
_wrapperState: {
wasMultiple: boolean,
},
};
type SelectWithWrapperState = HTMLSelectElement & {|
_wrapperState: {|wasMultiple: boolean|},
|};
function getDeclarationErrorAddendum() {
const ownerName = getCurrentFiberOwnerNameInDevOrNull();
@ -75,6 +73,7 @@ function updateOptions(
) {
type IndexableHTMLOptionsCollection = HTMLOptionsCollection & {
[key: number]: HTMLOptionElement,
...,
};
const options: IndexableHTMLOptionsCollection = node.options;

View File

@ -16,11 +16,9 @@ import type {ToStringValue} from './ToStringValue';
let didWarnValDefaultVal = false;
type TextAreaWithWrapperState = HTMLTextAreaElement & {
_wrapperState: {
initialValue: ToStringValue,
},
};
type TextAreaWithWrapperState = HTMLTextAreaElement & {|
_wrapperState: {|initialValue: ToStringValue|},
|};
/**
* Implements a <textarea> host component that allows setting `value`, and

View File

@ -7,12 +7,12 @@
* @flow
*/
type ValueTracker = {
type ValueTracker = {|
getValue(): string,
setValue(value: string): void,
stopTracking(): void,
};
type WrapperState = {_valueTracker?: ?ValueTracker};
|};
type WrapperState = {_valueTracker?: ?ValueTracker, ...};
type ElementWithValueTracker = HTMLInputElement & WrapperState;
function isCheckable(elem: HTMLInputElement) {

View File

@ -23,7 +23,7 @@ let reusableSVGContainer;
*/
const setInnerHTML = createMicrosoftUnsafeLocalFunction(function(
node: Element,
html: {valueOf(): {toString(): string}},
html: {valueOf(): {toString(): string, ...}, ...},
): void {
if (node.namespaceURI === Namespaces.svg) {
if (__DEV__) {

View File

@ -86,7 +86,9 @@ import isEventSupported from './isEventSupported';
*/
const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
// prettier-ignore
const elementListenerMap:
// $FlowFixMe Work around Flow bug
| WeakMap
| Map<
Document | Element | Node,

View File

@ -74,6 +74,7 @@ export function setAttemptHydrationAtCurrentPriority(
type PointerEvent = Event & {
pointerId: number,
relatedTarget: EventTarget | null,
...
};
import {

View File

@ -701,11 +701,10 @@ type Frame = {
childIndex: number,
context: Object,
footer: string,
...
};
type FrameDev = Frame & {
debugElementStack: Array<ReactElement>,
};
type FrameDev = Frame & {|debugElementStack: Array<ReactElement>|};
class ReactDOMServerRenderer {
threadID: ThreadID;
@ -1578,7 +1577,10 @@ class ReactDOMServerRenderer {
const innerMarkup = getNonChildrenInnerMarkup(props);
if (innerMarkup != null) {
children = [];
if (newlineEatingTags[tag] && innerMarkup.charAt(0) === '\n') {
if (
newlineEatingTags.hasOwnProperty(tag) &&
innerMarkup.charAt(0) === '\n'
) {
// text/html ignores the first character in these tags if it's a newline
// Prefer to break application/xml over text/html (for now) by adding
// a newline specifically to get eaten by the parser. (Alternately for

View File

@ -25,21 +25,21 @@ import is from 'shared/objectIs';
type BasicStateAction<S> = (S => S) | S;
type Dispatch<A> = A => void;
type Update<A> = {
type Update<A> = {|
action: A,
next: Update<A> | null,
};
|};
type UpdateQueue<A> = {
type UpdateQueue<A> = {|
last: Update<A> | null,
dispatch: any,
};
|};
type Hook = {
type Hook = {|
memoizedState: any,
queue: UpdateQueue<any> | null,
next: Hook | null,
};
|};
let currentlyRenderingComponent: Object | null = null;
let firstWorkInProgressHook: Hook | null = null;
@ -369,7 +369,7 @@ function useMemo<T>(nextCreate: () => T, deps: Array<mixed> | void | null): T {
return nextValue;
}
function useRef<T>(initialValue: T): {current: T} {
function useRef<T>(initialValue: T): {|current: T|} {
currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
workInProgressHook = createWorkInProgressHook();
const previousRef = workInProgressHook.memoizedState;

View File

@ -11,7 +11,7 @@ import invariant from 'shared/invariant';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {disableJavaScriptURLs} from 'shared/ReactFeatureFlags';
let ReactDebugCurrentFrame = ((null: any): {getStackAddendum(): string});
let ReactDebugCurrentFrame = ((null: any): {getStackAddendum(): string, ...});
if (__DEV__) {
ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
}

View File

@ -20,7 +20,12 @@ export type ReactModelRoot<T> = {|
model: T,
|};
type JSONValue = number | null | boolean | string | {[key: string]: JSONValue};
type JSONValue =
| number
| null
| boolean
| string
| {[key: string]: JSONValue, ...};
const PENDING = 0;
const RESOLVED = 1;
@ -49,10 +54,12 @@ type OpaqueResponseWithoutDecoder = {
modelRoot: ReactModelRoot<any>,
chunks: Map<number, Chunk>,
fromJSON: (key: string, value: JSONValue) => any,
...
};
type OpaqueResponse = OpaqueResponseWithoutDecoder & {
stringDecoder: StringDecoder,
...
};
export function createResponse(source: Source): OpaqueResponse {

View File

@ -17,6 +17,7 @@ import setElementCanTab from './shared/setElementCanTab';
type FocusItemProps = {
children?: React.Node,
onKeyDown?: KeyboardEvent => void,
...
};
type FocusGroupProps = {|

View File

@ -18,11 +18,10 @@ type FocusCellProps = {
children?: React.Node,
onKeyDown?: KeyboardEvent => void,
colSpan?: number,
...
};
type FocusRowProps = {
children: React.Node,
};
type FocusRowProps = {children: React.Node, ...};
type FocusTableProps = {|
children: React.Node,

View File

@ -23,9 +23,7 @@ type ContextMenuProps = {|
preventDefault: boolean,
|};
type ContextMenuState = {
pointerType: PointerType,
};
type ContextMenuState = {pointerType: PointerType, ...};
type ContextMenuEvent = {|
altKey: boolean,

View File

@ -29,6 +29,7 @@ type DragProps = {
onDragMove: (e: DragEvent) => void,
onDragEnd: (e: DragEvent) => void,
onDragChange: boolean => void,
...
};
type DragState = {|
@ -57,6 +58,7 @@ if (typeof window !== 'undefined' && window.PointerEvent === undefined) {
type EventData = {
diffX: number,
diffY: number,
...
};
type DragEventType = 'dragstart' | 'dragend' | 'dragchange' | 'dragmove';

View File

@ -36,6 +36,7 @@ type FocusState = {
isFocused: boolean,
isFocusVisible: boolean,
pointerType: PointerType,
...
};
type FocusProps = {
@ -44,6 +45,7 @@ type FocusProps = {
onFocus: (e: FocusEvent) => void,
onFocusChange: boolean => void,
onFocusVisibleChange: boolean => void,
...
};
type FocusEventType = 'focus' | 'blur' | 'focuschange' | 'focusvisiblechange';
@ -55,6 +57,7 @@ type FocusWithinProps = {
onBlurWithin?: (e: FocusEvent) => void,
onFocusWithinChange?: boolean => void,
onFocusWithinVisibleChange?: boolean => void,
...
};
type FocusWithinEventType =

View File

@ -24,6 +24,7 @@ type HoverProps = {
onHoverEnd: (e: HoverEvent) => void,
onHoverMove: (e: HoverEvent) => void,
onHoverStart: (e: HoverEvent) => void,
...
};
type HoverState = {
@ -32,6 +33,7 @@ type HoverState = {
isHovered: boolean,
isTouched?: boolean,
ignoreEmulatedMouseEvents?: boolean,
...
};
type HoverEventType = 'hoverstart' | 'hoverend' | 'hoverchange' | 'hovermove';

View File

@ -23,6 +23,7 @@ type InputResponderProps = {
onBeforeChange: (e: InputEvent) => void,
onChange: (e: InputEvent) => void,
onValueChange: (value: string | boolean) => void,
...
};
type InputEvent = {|

View File

@ -27,6 +27,7 @@ type PressProps = {|
right: number,
bottom: number,
left: number,
...
},
preventDefault: boolean,
onPress: (e: PressEvent) => void,
@ -65,6 +66,7 @@ type PressState = {
activePointerId: null | number,
shouldPreventClick: boolean,
touchEvent: null | Touch,
...
};
type PressEventType =

View File

@ -25,6 +25,7 @@ type ScrollProps = {
onScroll: ScrollEvent => void,
onScrollDragStart: ScrollEvent => void,
onScrollDragEnd: ScrollEvent => void,
...
};
type ScrollState = {
@ -35,6 +36,7 @@ type ScrollState = {
isTouching: boolean,
scrollLeft: number,
scrollTop: number,
...
};
type ScrollEventType =

View File

@ -26,6 +26,7 @@ type SwipeProps = {
onSwipeEnd: (e: SwipeEvent) => void,
onSwipeLeft: (e: SwipeEvent) => void,
onSwipeRight: (e: SwipeEvent) => void,
...
};
const targetEventTypes = ['pointerdown'];
@ -47,6 +48,7 @@ if (typeof window !== 'undefined' && window.PointerEvent === undefined) {
type EventData = {
diffX: number,
diffY: number,
...
};
type SwipeEventType = 'swipeleft' | 'swiperight' | 'swipeend' | 'swipemove';
@ -101,6 +103,7 @@ type SwipeState = {
swipeTarget: null | Element | Document,
x: number,
y: number,
...
};
const swipeResponderImpl = {

View File

@ -59,10 +59,9 @@ export type Props = Object;
export type Instance = {
node: Node,
canonical: ReactFabricHostComponent,
...
};
export type TextInstance = {
node: Node,
};
export type TextInstance = {node: Node, ...};
export type HydratableInstance = Instance | TextInstance;
export type PublicInstance = ReactFabricHostComponent;
export type Container = number;

View File

@ -35,6 +35,7 @@ export type Instance = {
_children: Array<Instance | number>,
_nativeTag: number,
viewConfig: ReactNativeBaseComponentViewConfig<>,
...
};
export type TextInstance = number;
export type HydratableInstance = Instance | TextInstance;

View File

@ -45,9 +45,8 @@ export type AttributeConfiguration<
TStyleProps = string,
> = $ReadOnly<{
[propName: TProps]: AttributeType,
style: $ReadOnly<{
[propName: TStyleProps]: AttributeType,
}>,
style: $ReadOnly<{[propName: TStyleProps]: AttributeType, ...}>,
...
}>;
export type ReactNativeBaseComponentViewConfig<
@ -62,18 +61,16 @@ export type ReactNativeBaseComponentViewConfig<
bubbled: string,
|}>,
|}>,
...,
}>,
Commands?: $ReadOnly<{
[commandName: string]: number,
}>,
Commands?: $ReadOnly<{[commandName: string]: number, ...}>,
directEventTypes?: $ReadOnly<{
[eventName: string]: $ReadOnly<{|
registrationName: string,
|}>,
...,
}>,
NativeProps?: $ReadOnly<{
[propName: string]: string,
}>,
NativeProps?: $ReadOnly<{[propName: string]: string, ...}>,
uiViewClassName: string,
validAttributes: AttributeConfiguration<TProps, TStyleProps>,
|}>;
@ -116,6 +113,7 @@ export type NativeMethods = {
onFail?: () => void,
): void,
setNativeProps(nativeProps: Object): void,
...
};
export type NativeMethodsMixinType = NativeMethods;
@ -126,10 +124,12 @@ type SecretInternalsType = {
computeComponentStackForErrorReporting(tag: number): string,
// TODO (bvaughn) Decide which additional types to expose here?
// And how much information to fill in for the above types.
...
};
type SecretInternalsFabricType = {
NativeMethodsMixin: NativeMethodsMixinType,
...
};
/**
@ -137,7 +137,7 @@ type SecretInternalsFabricType = {
* Provide minimal Flow typing for the high-level RN API and call it a day.
*/
export type ReactNativeType = {
NativeComponent: typeof ReactNativeComponent,
NativeComponent: _InternalReactNativeComponentClass<{...}>,
findHostInstance_DEPRECATED(
componentOrHandle: any,
): ?ElementRef<HostComponent<mixed>>,
@ -150,13 +150,14 @@ export type ReactNativeType = {
): any,
unmountComponentAtNode(containerTag: number): any,
unmountComponentAtNodeAndRemoveContainer(containerTag: number): any,
unstable_batchedUpdates: any, // TODO (bvaughn) Add types
// TODO (bvaughn) Add types
unstable_batchedUpdates: any,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsType,
...
};
export type ReactFabricType = {
NativeComponent: typeof ReactNativeComponent,
NativeComponent: _InternalReactNativeComponentClass<{...}>,
findHostInstance_DEPRECATED(componentOrHandle: any): ?HostComponent<mixed>,
findNodeHandle(componentOrHandle: any): ?number,
dispatchCommand(handle: any, command: string, args: Array<any>): void,
@ -167,6 +168,7 @@ export type ReactFabricType = {
): any,
unmountComponentAtNode(containerTag: number): any,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsFabricType,
...
};
export type ReactNativeEventTarget = {
@ -176,7 +178,9 @@ export type ReactNativeEventTarget = {
viewConfig: ReactNativeBaseComponentViewConfig<>,
currentProps: Object,
_internalInstanceHandle: Object,
...
},
...
};
export type ReactFaricEventTouch = {
@ -190,6 +194,7 @@ export type ReactFaricEventTouch = {
target: number,
timestamp: number,
force: number,
...
};
export type ReactFaricEvent = {
@ -197,4 +202,5 @@ export type ReactFaricEvent = {
changedTouches: Array<ReactFaricEventTouch>,
targetTouches: Array<ReactFaricEventTouch>,
target: number,
...
};

View File

@ -31,6 +31,7 @@ type Container = {
rootID: string,
children: Array<Instance | TextInstance>,
pendingChildren: Array<Instance | TextInstance>,
...
};
type Props = {
prop: any,
@ -40,6 +41,7 @@ type Props = {
left?: null | number,
right?: null | number,
top?: null | number,
...
};
type Instance = {|
type: string,
@ -315,7 +317,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
type: string,
oldProps: Props,
newProps: Props,
): null | {} {
): null | {...} {
if (type === 'errorInCompletePhase') {
throw new Error('Error in host config.');
}

View File

@ -11,13 +11,13 @@ import type {Fiber} from './ReactFiber';
import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
export type CapturedValue<T> = {
export type CapturedValue<T> = {|
value: T,
source: Fiber | null,
stack: string | null,
};
|};
export type CapturedError = {
export type CapturedError = {|
componentName: ?string,
componentStack: string,
error: mixed,
@ -25,7 +25,7 @@ export type CapturedError = {
errorBoundaryFound: boolean,
errorBoundaryName: string | null,
willRetry: boolean,
};
|};
export function createCapturedValue<T>(
value: T,

View File

@ -120,6 +120,7 @@ export type Dependencies = {
ReactEventResponder<any, any>,
ReactEventResponderInstance<any, any>,
> | null,
...
};
// A Fiber is work on a Component that needs to be done or was done. There can
@ -170,7 +171,10 @@ export type Fiber = {|
// The ref last used to attach this node.
// I'll avoid adding an owner field for prod and model that as functions.
ref: null | (((handle: mixed) => void) & {_stringRef: ?string}) | RefObject,
ref:
| null
| (((handle: mixed) => void) & {_stringRef: ?string, ...})
| RefObject,
// Input is the data coming into process this fiber. Arguments. Props.
pendingProps: any, // This type will be more specific once we overload the tag.

View File

@ -914,8 +914,11 @@ function emptyPortalContainer(current: Fiber) {
return;
}
const portal: {containerInfo: Container, pendingChildren: ChildSet} =
current.stateNode;
const portal: {
containerInfo: Container,
pendingChildren: ChildSet,
...
} = current.stateNode;
const {containerInfo} = portal;
const emptyChildSet = createContainerChildSet(containerInfo);
replaceContainerChildren(containerInfo, emptyChildSet);
@ -938,6 +941,7 @@ function commitContainer(finishedWork: Fiber) {
const portalOrRoot: {
containerInfo: Container,
pendingChildren: ChildSet,
...
} = finishedWork.stateNode;
const {containerInfo, pendingChildren} = portalOrRoot;
replaceContainerChildren(containerInfo, pendingChildren);

View File

@ -435,6 +435,7 @@ if (supportsMutation) {
const portalOrRoot: {
containerInfo: Container,
pendingChildren: ChildSet,
...
} = workInProgress.stateNode;
const childrenUnchanged = workInProgress.firstEffect === null;
if (childrenUnchanged) {

View File

@ -59,7 +59,7 @@ import {
const {ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals;
export type Dispatcher = {
export type Dispatcher = {|
readContext<T>(
context: ReactContext<T>,
observedBits: void | number | boolean,
@ -74,7 +74,7 @@ export type Dispatcher = {
context: ReactContext<T>,
observedBits: void | number | boolean,
): T,
useRef<T>(initialValue: T): {current: T},
useRef<T>(initialValue: T): {|current: T|},
useEffect(
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
@ -86,7 +86,7 @@ export type Dispatcher = {
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T,
useMemo<T>(nextCreate: () => T, deps: Array<mixed> | void | null): T,
useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void,
@ -99,25 +99,24 @@ export type Dispatcher = {
useTransition(
config: SuspenseConfig | void | null,
): [(() => void) => void, boolean],
};
|};
type Update<S, A> = {
type Update<S, A> = {|
expirationTime: ExpirationTime,
suspenseConfig: null | SuspenseConfig,
action: A,
eagerReducer: ((S, A) => S) | null,
eagerState: S | null,
next: Update<S, A>,
priority?: ReactPriorityLevel,
};
|};
type UpdateQueue<S, A> = {
type UpdateQueue<S, A> = {|
pending: Update<S, A> | null,
dispatch: (A => mixed) | null,
lastRenderedReducer: ((S, A) => S) | null,
lastRenderedState: S | null,
};
|};
export type HookType =
| 'useState'
@ -139,27 +138,23 @@ if (__DEV__) {
didWarnAboutMismatchedHooksForComponent = new Set();
}
export type Hook = {
export type Hook = {|
memoizedState: any,
baseState: any,
baseQueue: Update<any, any> | null,
queue: UpdateQueue<any, any> | null,
next: Hook | null,
};
|};
type Effect = {
type Effect = {|
tag: HookEffectTag,
create: () => (() => void) | void,
destroy: (() => void) | void,
deps: Array<mixed> | null,
next: Effect,
};
|};
export type FunctionComponentUpdateQueue = {
lastEffect: Effect | null,
};
export type FunctionComponentUpdateQueue = {|lastEffect: Effect | null|};
export type TimeoutConfig = {|
timeoutMs: number,
@ -885,7 +880,7 @@ function pushEffect(tag, create, destroy, deps) {
return effect;
}
function mountRef<T>(initialValue: T): {current: T} {
function mountRef<T>(initialValue: T): {|current: T|} {
const hook = mountWorkInProgressHook();
const ref = {current: initialValue};
if (__DEV__) {
@ -895,7 +890,7 @@ function mountRef<T>(initialValue: T): {current: T} {
return ref;
}
function updateRef<T>(initialValue: T): {current: T} {
function updateRef<T>(initialValue: T): {|current: T|} {
const hook = updateWorkInProgressHook();
return hook.memoizedState;
}
@ -991,7 +986,7 @@ function updateLayoutEffect(
function imperativeHandleEffect<T>(
create: () => T,
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
) {
if (typeof ref === 'function') {
const refCallback = ref;
@ -1020,7 +1015,7 @@ function imperativeHandleEffect<T>(
}
function mountImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void {
@ -1047,7 +1042,7 @@ function mountImperativeHandle<T>(
}
function updateImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void {
@ -1464,7 +1459,7 @@ if (__DEV__) {
return mountEffect(create, deps);
},
useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void {
@ -1509,7 +1504,7 @@ if (__DEV__) {
ReactCurrentDispatcher.current = prevDispatcher;
}
},
useRef<T>(initialValue: T): {current: T} {
useRef<T>(initialValue: T): {|current: T|} {
currentHookNameInDev = 'useRef';
mountHookTypesDev();
return mountRef(initialValue);
@ -1584,7 +1579,7 @@ if (__DEV__) {
return mountEffect(create, deps);
},
useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void {
@ -1626,7 +1621,7 @@ if (__DEV__) {
ReactCurrentDispatcher.current = prevDispatcher;
}
},
useRef<T>(initialValue: T): {current: T} {
useRef<T>(initialValue: T): {|current: T|} {
currentHookNameInDev = 'useRef';
updateHookTypesDev();
return mountRef(initialValue);
@ -1701,7 +1696,7 @@ if (__DEV__) {
return updateEffect(create, deps);
},
useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void {
@ -1743,7 +1738,7 @@ if (__DEV__) {
ReactCurrentDispatcher.current = prevDispatcher;
}
},
useRef<T>(initialValue: T): {current: T} {
useRef<T>(initialValue: T): {|current: T|} {
currentHookNameInDev = 'useRef';
updateHookTypesDev();
return updateRef(initialValue);
@ -1822,7 +1817,7 @@ if (__DEV__) {
return mountEffect(create, deps);
},
useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void {
@ -1868,7 +1863,7 @@ if (__DEV__) {
ReactCurrentDispatcher.current = prevDispatcher;
}
},
useRef<T>(initialValue: T): {current: T} {
useRef<T>(initialValue: T): {|current: T|} {
currentHookNameInDev = 'useRef';
warnInvalidHookAccess();
mountHookTypesDev();
@ -1953,7 +1948,7 @@ if (__DEV__) {
return updateEffect(create, deps);
},
useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void {
@ -1999,7 +1994,7 @@ if (__DEV__) {
ReactCurrentDispatcher.current = prevDispatcher;
}
},
useRef<T>(initialValue: T): {current: T} {
useRef<T>(initialValue: T): {|current: T|} {
currentHookNameInDev = 'useRef';
warnInvalidHookAccess();
updateHookTypesDev();

View File

@ -16,6 +16,7 @@ export type ContextDependency<T> = {
context: ReactContext<T>,
observedBits: number,
next: ContextDependency<mixed> | null,
...
};
import {isPrimaryRenderer} from './ReactFiberHostConfig';

View File

@ -100,6 +100,7 @@ export type FiberRoot = {
...BaseFiberRootProperties,
...ProfilingOnlyFiberRootProperties,
...SuspenseCallbackOnlyFiberRootProperties,
...
};
function FiberRootNode(containerInfo, tag, hydrate) {

View File

@ -9,9 +9,7 @@
import type {Fiber} from './ReactFiber';
export type StackCursor<T> = {
current: T,
};
export type StackCursor<T> = {|current: T|};
const valueStack: Array<any> = [];

View File

@ -20,6 +20,7 @@ import {
export type SuspenseHydrationCallbacks = {
onHydrated?: (suspenseInstance: SuspenseInstance) => void,
onDeleted?: (suspenseInstance: SuspenseInstance) => void,
...
};
// A null SuspenseState represents an unsuspended normal Suspense boundary.

View File

@ -211,9 +211,9 @@ const RootCompleted = 5;
export type Thenable = {
then(resolve: () => mixed, reject?: () => mixed): Thenable | void,
// Special flag to opt out of tracing interactions across a Suspense boundary.
__reactDoNotTraceInteractions?: boolean,
...
};
// Describes where we are in the React execution stack

View File

@ -23,6 +23,7 @@ export type ProfilerTimer = {
startProfilerTimer(fiber: Fiber): void,
stopProfilerTimerIfRunning(fiber: Fiber): void,
stopProfilerTimerIfRunningAndRecordDelta(fiber: Fiber): void,
...
};
let commitTime: number = 0;

View File

@ -107,7 +107,7 @@ import {
import invariant from 'shared/invariant';
import {getCurrentPriorityLevel} from './SchedulerWithReactIntegration';
export type Update<State> = {
export type Update<State> = {|
expirationTime: ExpirationTime,
suspenseConfig: null | SuspenseConfig,
@ -117,20 +117,18 @@ export type Update<State> = {
next: Update<State>,
//DEV only
// DEV only
priority?: ReactPriorityLevel,
};
|};
type SharedQueue<State> = {
pending: Update<State> | null,
};
type SharedQueue<State> = {|pending: Update<State> | null|};
export type UpdateQueue<State> = {
export type UpdateQueue<State> = {|
baseState: State,
baseQueue: Update<State> | null,
shared: SharedQueue<State>,
effects: Array<Update<State>> | null,
};
|};
export const UpdateState = 0;
export const ReplaceState = 1;

View File

@ -46,9 +46,7 @@ if (enableSchedulerTracing) {
export type ReactPriorityLevel = 99 | 98 | 97 | 96 | 95 | 90;
export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
type SchedulerCallbackOptions = {
timeout?: number,
};
type SchedulerCallbackOptions = {timeout?: number, ...};
const fakeCallbackNode = {};

View File

@ -488,7 +488,7 @@ export function injectIntoGlobalHook(globalObject: any): void {
hook.onScheduleFiberRoot = function(
id: number,
root: FiberRoot,
children: mixed,
children: ReactNodeList,
) {
if (!isPerformingRefresh) {
// If it was intentionally scheduled, don't attempt to restore.

View File

@ -26,6 +26,7 @@ type OpaqueRequest = {
children: ReactNodeList,
completedChunks: Array<Uint8Array>,
flowing: boolean,
...
};
export function createRequest(

View File

@ -95,14 +95,13 @@ type ReactJSONValue =
| Array<ReactModel>
| ReactModelObject;
type ReactModelObject = {
+[key: string]: ReactModel,
};
type ReactModelObject = {+[key: string]: ReactModel, ...};
type Segment = {
id: number,
model: ReactModel,
ping: () => void,
...
};
type OpaqueRequest = {
@ -114,6 +113,7 @@ type OpaqueRequest = {
completedErrorChunks: Array<Uint8Array>,
flowing: boolean,
toJSON: (key: string, value: ReactModel) => ReactJSONValue,
...
};
export function createRequest(

View File

@ -11,7 +11,9 @@ import type {Writable} from 'stream';
type MightBeFlushable = {
flush?: () => void,
flushHeaders?: () => void, // Legacy
// Legacy
flushHeaders?: () => void,
...
};
export type Destination = Writable & MightBeFlushable;

View File

@ -27,21 +27,21 @@ import type {ReactElement} from 'shared/ReactElementType';
type BasicStateAction<S> = (S => S) | S;
type Dispatch<A> = A => void;
type Update<A> = {
type Update<A> = {|
action: A,
next: Update<A> | null,
};
|};
type UpdateQueue<A> = {
type UpdateQueue<A> = {|
first: Update<A> | null,
dispatch: any,
};
|};
type Hook = {
type Hook = {|
memoizedState: any,
queue: UpdateQueue<any> | null,
next: Hook | null,
};
|};
const {ReactCurrentDispatcher} = ReactSharedInternals;
@ -340,7 +340,7 @@ class ReactShallowRenderer {
return nextValue;
};
const useRef = <T>(initialValue: T): {current: T} => {
const useRef = <T>(initialValue: T): {|current: T|} => {
this._validateCurrentlyRenderingComponent();
this._createWorkInProgressHook();
const previousRef = (this._workInProgressHook: any).memoizedState;

View File

@ -195,7 +195,7 @@ export function prepareUpdate(
newProps: Props,
rootContainerInstance: Container,
hostContext: Object,
): null | {} {
): null | {...} {
return UPDATE_SIGNAL;
}
@ -246,7 +246,7 @@ export const supportsMutation = true;
export function commitUpdate(
instance: Instance,
updatePayload: {},
updatePayload: {...},
type: string,
oldProps: Props,
newProps: Props,

View File

@ -50,11 +50,12 @@ import {ConcurrentRoot, LegacyRoot} from 'shared/ReactRootTags';
type TestRendererOptions = {
createNodeMock: (element: React$Element<any>) => any,
unstable_isConcurrent: boolean,
...
};
type ReactTestRendererJSON = {|
type: string,
props: {[propName: string]: any},
props: {[propName: string]: any, ...},
children: null | Array<ReactTestRendererNode>,
$$typeof?: Symbol, // Optional because we add it with defineProperty().
|};
@ -64,6 +65,7 @@ type FindOptions = $Shape<{
// performs a "greedy" search: if a matching node is found, will continue
// to search within the matching node's children. (default: true)
deep: boolean,
...
}>;
export type Predicate = (node: ReactTestInstance) => ?boolean;

View File

@ -86,7 +86,7 @@ export function useReducer<S, I, A>(
return dispatcher.useReducer(reducer, initialArg, init);
}
export function useRef<T>(initialValue: T): {current: T} {
export function useRef<T>(initialValue: T): {|current: T|} {
const dispatcher = resolveDispatcher();
return dispatcher.useRef(initialValue);
}
@ -124,7 +124,7 @@ export function useMemo(
}
export function useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
ref: {|current: T | null|} | ((inst: T | null) => mixed) | null | void,
create: () => T,
inputs: Array<mixed> | void | null,
): void {

View File

@ -8,10 +8,10 @@
*/
type Heap = Array<Node>;
type Node = {
type Node = {|
id: number,
sortIndex: number,
};
|};
export function push(heap: Heap, node: Node): void {
const index = heap.length;

View File

@ -103,7 +103,11 @@ export function stopLoggingProfilingEvents(): ArrayBuffer | null {
}
export function markTaskStart(
task: {id: number, priorityLevel: PriorityLevel},
task: {
id: number,
priorityLevel: PriorityLevel,
...
},
ms: number,
) {
if (enableProfiling) {
@ -122,6 +126,7 @@ export function markTaskCompleted(
task: {
id: number,
priorityLevel: PriorityLevel,
...
},
ms: number,
) {
@ -140,6 +145,7 @@ export function markTaskCanceled(
task: {
id: number,
priorityLevel: PriorityLevel,
...
},
ms: number,
) {
@ -156,6 +162,7 @@ export function markTaskErrored(
task: {
id: number,
priorityLevel: PriorityLevel,
...
},
ms: number,
) {
@ -171,7 +178,11 @@ export function markTaskErrored(
}
export function markTaskRun(
task: {id: number, priorityLevel: PriorityLevel},
task: {
id: number,
priorityLevel: PriorityLevel,
...
},
ms: number,
) {
if (enableProfiling) {
@ -187,7 +198,7 @@ export function markTaskRun(
}
}
export function markTaskYield(task: {id: number}, ms: number) {
export function markTaskYield(task: {id: number, ...}, ms: number) {
if (enableProfiling) {
profilingState[PRIORITY] = NoPriority;
profilingState[CURRENT_TASK_ID] = 0;

View File

@ -45,15 +45,12 @@ export type Subscriber = {
// A batch of work has completed for a set of interactions.
// Work is done by a "thread" which is identified by a unique ID.
onWorkStopped: (interactions: Set<Interaction>, threadID: number) => void,
...
};
export type InteractionsRef = {
current: Set<Interaction>,
};
export type InteractionsRef = {|current: Set<Interaction>|};
export type SubscriberRef = {
current: Subscriber | null,
};
export type SubscriberRef = {|current: Subscriber | null|};
const DEFAULT_THREAD_ID = 0;

View File

@ -30,6 +30,7 @@ export type ReactDOMResponderEvent = {
pointerType: PointerType,
target: Element | Document,
type: string,
...
};
export type ReactDOMEventResponder = ReactEventResponder<
@ -72,4 +73,5 @@ export type ReactDOMResponderContext = {
// Used for controller components
enqueueStateRestore(Element | Document): void,
getResponderNode(): Element | null,
...
};

View File

@ -7,24 +7,23 @@
* @flow
*/
export type Source = {
export type Source = {|
fileName: string,
lineNumber: number,
};
|};
export type ReactElement = {
export type ReactElement = {|
$$typeof: any,
type: any,
key: any,
ref: any,
props: any,
_owner: any, // ReactInstance or ReactFiber
// ReactFiber
_owner: any,
// __DEV__
_store: {
validated: boolean,
},
_store: {validated: boolean, ...},
_self: React$Element<any>,
_shadowChildren: any,
_source: Source,
};
|};

View File

@ -9,20 +9,23 @@
export type Thenable<T, R> = {
then(resolve: (T) => mixed, reject: (mixed) => mixed): R,
...
};
export type LazyComponent<T> = {
$$typeof: Symbol | number,
_ctor: () => Thenable<{default: T}, mixed>,
_ctor: () => Thenable<{default: T, ...}, mixed>,
_status: 0 | 1 | 2,
_result: any,
...
};
type ResolvedLazyComponent<T> = {
$$typeof: Symbol | number,
_ctor: () => Thenable<{default: T}, mixed>,
_ctor: () => Thenable<{default: T, ...}, mixed>,
_status: 1,
_result: any,
...
};
export const Uninitialized = -1;

View File

@ -31,12 +31,15 @@ export type ReactProvider<T> = {
props: {
value: T,
children?: ReactNodeList,
...
},
...
};
export type ReactProviderType<T> = {
$$typeof: Symbol | number,
_context: ReactContext<T>,
...
};
export type ReactConsumer<T> = {
@ -47,23 +50,23 @@ export type ReactConsumer<T> = {
props: {
children: (value: T) => ReactNodeList,
unstable_observedBits?: number,
...
},
...
};
export type ReactContext<T> = {
$$typeof: Symbol | number,
Consumer: ReactContext<T>,
Provider: ReactProviderType<T>,
_calculateChangedBits: ((a: T, b: T) => number) | null,
_currentValue: T,
_currentValue2: T,
_threadCount: number,
// DEV only
_currentRenderer?: Object | null,
_currentRenderer2?: Object | null,
...
};
export type ReactPortal = {
@ -73,6 +76,7 @@ export type ReactPortal = {
children: ReactNodeList,
// TODO: figure out the API for cross-renderer implementation.
implementation: any,
...
};
export type RefObject = {|
@ -97,6 +101,7 @@ export type ReactEventResponder<E, C> = {
displayName: string,
targetEventTypes: null | Array<string>,
targetPortalPropagation: boolean,
rootEventTypes: null | Array<string>,
getInitialState: null | ((props: Object) => Object),
onEvent:
| null
@ -106,6 +111,7 @@ export type ReactEventResponder<E, C> = {
| ((event: E, context: C, props: Object, state: Object) => void),
onMount: null | ((context: C, props: Object, state: Object) => void),
onUnmount: null | ((context: C, props: Object, state: Object) => void),
...
};
export type EventPriority = 0 | 1 | 2;
@ -152,6 +158,7 @@ export type ReactFundamentalImpl<C, H> = {
) => void,
onHydrate?: (context: C, props: Object, state: Object) => boolean,
onFocus?: (context: C, props: Object, state: Object) => boolean,
...
};
export type ReactFundamentalComponent<C, H> = {|

View File

@ -10,7 +10,7 @@
/**
* @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
*/
const supportedInputTypes: {[key: string]: true | void} = {
const supportedInputTypes: {[key: string]: true | void, ...} = {
color: true,
date: true,
datetime: true,

View File

@ -8,5 +8,5 @@
*/
'use strict';
/*:: export type ErrorMap = { [id: string]: string; }; */
/*:: export type ErrorMap = { [id: string]: string, ... }; */

View File

@ -49,4 +49,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
[version]
^0.72.0
^0.84.0

View File

@ -32,9 +32,7 @@ declare module 'ReactFeatureFlags' {
// ReactFiberErrorDialog www fork
declare module 'ReactFiberErrorDialog' {
declare module.exports: {
showErrorDialog: (error: mixed) => boolean,
};
declare module.exports: {showErrorDialog: (error: mixed) => boolean, ...};
}
// EventListener www fork
@ -45,7 +43,7 @@ declare module 'EventListener' {
type: string,
callback: Function,
priority?: number,
options?: {passive: boolean},
options?: {passive: boolean, ...},
) => mixed,
capture: (target: Element, type: string, callback: Function) => mixed,
captureWithPassiveFlag: (
@ -54,5 +52,6 @@ declare module 'EventListener' {
callback: Function,
passive: boolean,
) => mixed,
...
};
}

View File

@ -37,17 +37,18 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
declare export function flattenStyle(style: any): any;
declare export var RCTEventEmitter: {
register: (eventEmitter: mixed) => void,
...
};
declare export var TextInputState: {
blurTextInput: (object: any) => void,
focusTextInput: (object: any) => void,
...
};
declare export var ReactFiberErrorDialog: {
showErrorDialog: (error: CapturedError) => boolean,
...
};
declare export var Platform: {
OS: string,
};
declare export var Platform: {OS: string, ...};
declare export var UIManager: {
customBubblingEventTypes: Object,
customDirectEventTypes: Object,
@ -90,13 +91,16 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
height?: number,
format?: 'png' | 'jpeg',
quality?: number,
...
},
) => Promise<any>,
setJSResponder: (reactTag: number, blockNativeResponder: boolean) => void,
clearJSResponder: () => void,
...
};
declare export var BatchedBridge: {
registerCallableModule: (name: string, module: Object) => void,
...
};
declare export var ReactNativeViewConfigRegistry: {
customBubblingEventTypes: Object,
@ -105,6 +109,7 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
register: (name: string, callback: ViewConfigGetter) => string,
get: (name: string) => ReactNativeBaseComponentViewConfig,
...
};
}
@ -151,6 +156,7 @@ declare var nativeFabricUIManager: {
onFail: () => void,
onSuccess: MeasureLayoutOnSuccessCallback,
) => void,
...
};
declare module 'View' {

View File

@ -6,7 +6,7 @@
*/
'use strict';
const babylon = require('babylon');
const babelParser = require('@babel/parser');
const fs = require('fs');
const through = require('through2');
const traverse = require('@babel/traverse').default;
@ -14,9 +14,9 @@ const gs = require('glob-stream');
const evalToString = require('../shared/evalToString');
const babylonOptions = {
const parserOptions = {
sourceType: 'module',
// As a parser, babylon has its own options and we can't directly
// babelParser has its own options and we can't directly
// import/require a babel preset. It should be kept **the same** as
// the `babel-plugin-syntax-*` ones specified in
// https://github.com/facebook/fbjs/blob/master/packages/babel-preset-fbjs/configure.js
@ -40,7 +40,7 @@ function transform(file, enc, cb) {
let ast;
try {
ast = babylon.parse(source, babylonOptions);
ast = babelParser.parse(source, parserOptions);
} catch (error) {
console.error('Failed to parse source file:', file.path);
throw error;

View File

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @flow strict-local
*/
'use strict';

View File

@ -27,11 +27,13 @@ const customBubblingEventTypes: {
bubbled: string,
|}>,
|}>,
...,
} = {};
const customDirectEventTypes: {
[eventName: string]: $ReadOnly<{|
registrationName: string,
|}>,
...,
} = {};
exports.customBubblingEventTypes = customBubblingEventTypes;

View File

@ -2723,7 +2723,7 @@ babel-types@^6.24.1, babel-types@^6.26.0:
lodash "^4.17.4"
to-fast-properties "^1.0.3"
babylon@6.18.0, babylon@^6.18.0:
babylon@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"
integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==
@ -5696,10 +5696,10 @@ flatted@^2.0.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==
flow-bin@^0.72.0:
version "0.72.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.72.0.tgz#12051180fb2db7ccb728fefe67c77e955e92a44d"
integrity sha1-EgURgPstt8y3KP7+Z8d+lV6SpE0=
flow-bin@^0.84.0:
version "0.84.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.84.0.tgz#4cb2364c750fb37a7840524fa62456b53f64cdcb"
integrity sha512-ocji8eEYp+YfICsm+F6cIHUcD7v5sb0/ADEXm6gyUKdjQzmSckMrPUdZtyfP973t3YGHKliUMxMvIBHyR5LbXQ==
fluent-syntax@0.13.0:
version "0.13.0"