Skip to content

Commit

Permalink
Flow: implicit-inexact-object=error (#25210)
Browse files Browse the repository at this point in the history
* implicit-inexact-object=error
* default everything ambiguous to exact object
* inexact where exact causes errors
  • Loading branch information
kassens committed Sep 9, 2022
1 parent 37cc6bf commit 8a9e7b6
Show file tree
Hide file tree
Showing 83 changed files with 323 additions and 292 deletions.
29 changes: 17 additions & 12 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type JSONValue =
| null
| boolean
| string
| {+[key: string]: JSONValue}
| {|+[key: string]: JSONValue|}
| $ReadOnlyArray<JSONValue>;

const PENDING = 0;
Expand All @@ -43,36 +43,36 @@ const RESOLVED_MODULE = 2;
const INITIALIZED = 3;
const ERRORED = 4;

type PendingChunk = {
type PendingChunk = {|
_status: 0,
_value: null | Array<() => mixed>,
_response: Response,
then(resolve: () => mixed): void,
};
type ResolvedModelChunk = {
|};
type ResolvedModelChunk = {|
_status: 1,
_value: UninitializedModel,
_response: Response,
then(resolve: () => mixed): void,
};
type ResolvedModuleChunk<T> = {
|};
type ResolvedModuleChunk<T> = {|
_status: 2,
_value: ModuleReference<T>,
_response: Response,
then(resolve: () => mixed): void,
};
type InitializedChunk<T> = {
|};
type InitializedChunk<T> = {|
_status: 3,
_value: T,
_response: Response,
then(resolve: () => mixed): void,
};
type ErroredChunk = {
|};
type ErroredChunk = {|
_status: 4,
_value: Error,
_response: Response,
then(resolve: () => mixed): void,
};
|};
type SomeChunk<T> =
| PendingChunk
| ResolvedModelChunk
Expand Down Expand Up @@ -129,17 +129,20 @@ function readRoot<T>(): T {
}

function createPendingChunk(response: Response): PendingChunk {
// $FlowFixMe Flow doesn't support functions as constructors
return new Chunk(PENDING, null, response);
}

function createErrorChunk(response: Response, error: Error): ErroredChunk {
// $FlowFixMe Flow doesn't support functions as constructors
return new Chunk(ERRORED, error, response);
}

function createInitializedChunk<T>(
response: Response,
value: T,
): InitializedChunk<T> {
// $FlowFixMe Flow doesn't support functions as constructors
return new Chunk(INITIALIZED, value, response);
}

Expand Down Expand Up @@ -168,13 +171,15 @@ function createResolvedModelChunk(
response: Response,
value: UninitializedModel,
): ResolvedModelChunk {
// $FlowFixMe Flow doesn't support functions as constructors
return new Chunk(RESOLVED_MODEL, value, response);
}

function createResolvedModuleChunk<T>(
response: Response,
value: ModuleReference<T>,
): ResolvedModuleChunk<T> {
// $FlowFixMe Flow doesn't support functions as constructors
return new Chunk(RESOLVED_MODULE, value, response);
}

Expand Down Expand Up @@ -333,7 +338,7 @@ export function parseModelString(

export function parseModelTuple(
response: Response,
value: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
value: {|+[key: string]: JSONValue|} | $ReadOnlyArray<JSONValue>,
): any {
const tuple: [mixed, mixed, mixed, mixed] = (value: any);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import type {ResponseBase} from './ReactFlightClient';
import type {StringDecoder} from './ReactFlightClientHostConfig';

export type Response = ResponseBase & {
export type Response = ResponseBase & {|
_partialRow: string,
_fromJSON: (key: string, value: JSONValue) => any,
_stringDecoder: StringDecoder,
};
|};

export type UninitializedModel = string;

Expand Down
8 changes: 4 additions & 4 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ type Dispatch<A> = A => void;

let primitiveStackCache: null | Map<string, Array<any>> = null;

type Hook = {
type Hook = {|
memoizedState: any,
next: Hook | null,
};
|};

function getPrimitiveStackCache(): Map<string, Array<any>> {
// This initializes a cache of all primitive hooks so that the top
Expand Down Expand Up @@ -371,12 +371,12 @@ const DispatcherProxy = new Proxy(Dispatcher, DispatcherProxyHandler);

// Inspect

export type HookSource = {
export type HookSource = {|
lineNumber: number | null,
columnNumber: number | null,
fileName: string | null,
functionName: string | null,
};
|};

export type HooksNode = {
id: number | null,
Expand Down
12 changes: 6 additions & 6 deletions packages/react-devtools-shared/src/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ export type LoggerEvent =
|}
| {|
+event_name: 'select-element',
+metadata: {
+metadata: {|
+source: string,
},
|},
|}
| {|
+event_name: 'inspect-element-button-clicked',
|}
| {|
+event_name: 'profiling-start',
+metadata: {
+metadata: {|
+current_tab: string,
},
|},
|}
| {|
+event_name: 'profiler-tab-changed',
+metadata: {
+metadata: {|
+tabId: string,
},
|},
|}
| {|
+event_name: 'settings-changed',
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/backend/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ export function patch({
showInlineWarningsAndErrors,
hideConsoleLogsInStrictMode,
browserTheme,
}: {
}: {|
appendComponentStack: boolean,
breakOnConsoleErrors: boolean,
showInlineWarningsAndErrors: boolean,
hideConsoleLogsInStrictMode: boolean,
browserTheme: BrowserTheme,
}): void {
|}): void {
// Settings may change after we've patched the console.
// Using a shared ref allows the patch function to read the latest values.
consoleSettingsRef.appendComponentStack = appendComponentStack;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import type {
DisplayDensity,
} from './devtools/views/Settings/SettingsContext';

export const THEME_STYLES: {[style: Theme | DisplayDensity]: any} = {
export const THEME_STYLES: {[style: Theme | DisplayDensity]: any, ...} = {
light: {
'--color-attribute-name': '#ef6632',
'--color-attribute-name-not-editable': '#23272f',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function useContextMenu({
data: Object,
id: string,
onChange?: OnChangeFn,
ref: {current: ElementRef<*> | null},
ref: {|current: ElementRef<*> | null|},
|}) {
const {showMenu} = useContext<RegistryContextType>(RegistryContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type TreeProps = {|
badgeClassName: string,
actions: React$Node,
className: string,
clearMessages: () => {},
clearMessages: () => void,
entries: Array<[string, number]>,
isTransitionPending: boolean,
label: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export type TooltipFiberData = {|
name: string,
|};

export type Props = {
export type Props = {|
fiberData: ChartNode,
};
|};

export default function HoveredFiberInfo({fiberData}: Props) {
const {profilerStore} = useContext(StoreContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ type ListProps = {|
width: number,
|};

type DragState = {
type DragState = {|
commitIndex: number,
left: number,
sizeIncrement: number,
};
|};

function List({
commitData,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ export function installHook(target: any): DevToolsHook | null {
function patchConsoleForInitialRenderInStrictMode({
hideConsoleLogsInStrictMode,
browserTheme,
}: {
}: {|
hideConsoleLogsInStrictMode: boolean,
browserTheme: BrowserTheme,
}) {
|}) {
const overrideConsoleMethods = [
'error',
'group',
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/hooks/astUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export type Position = {|
column: number,
|};

export type SourceFileASTWithHookDetails = {
export type SourceFileASTWithHookDetails = {|
sourceFileAST: File,
line: number,
source: string,
};
|};

export const NO_HOOK_NAME = '<no-hook>';

Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/inspectedElementCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ export function checkForUpdate({
element,
refresh,
store,
}: {
}: {|
bridge: FrontendBridge,
element: Element,
refresh: RefreshFunction,
store: Store,
}): void {
|}): void {
const {id} = element;
const rendererID = store.getRendererIDForElement(id);
if (rendererID != null) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/react-devtools-timeline/src/CanvasPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function CanvasPage({profilerData, viewState}: Props) {
className={styles.CanvasPage}
style={{backgroundColor: COLORS.BACKGROUND}}>
<AutoSizer>
{({height, width}: {height: number, width: number}) => (
{({height, width}: {|height: number, width: number|}) => (
<AutoSizedCanvas
data={profilerData}
height={height}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-timeline/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export type Return<T> = Return_<*, T>;

// Project types

export type ErrorStackFrame = {
export type ErrorStackFrame = {|
fileName: string,
lineNumber: number,
columnNumber: number,
};
|};

export type Milliseconds = number;

Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-timeline/src/utils/useSmartTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function useSmartTooltip({
canvasRef,
mouseX,
mouseY,
}: {
}: {|
canvasRef: {|current: HTMLCanvasElement | null|},
mouseX: number,
mouseY: number,
}) {
|}) {
const ref = useRef<HTMLElement | null>(null);

// HACK: Browser extension reports window.innerHeight of 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const HIDDEN_RECT = {
};

export class ResizableView extends View {
_canvasRef: {current: HTMLCanvasElement | null};
_canvasRef: {|current: HTMLCanvasElement | null|};
_layoutState: LayoutState;
_mutableViewStateKey: string;
_resizeBar: ResizeBarView;
Expand All @@ -60,7 +60,7 @@ export class ResizableView extends View {
frame: Rect,
subview: View,
viewState: ViewState,
canvasRef: {current: HTMLCanvasElement | null},
canvasRef: {|current: HTMLCanvasElement | null|},
label: string,
) {
super(surface, frame, noopLayout);
Expand Down
Loading

0 comments on commit 8a9e7b6

Please sign in to comment.