Skip to content

Commit

Permalink
straightford explicit types
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens committed Sep 13, 2022
1 parent 271bf90 commit 3d9bba3
Show file tree
Hide file tree
Showing 52 changed files with 175 additions and 139 deletions.
2 changes: 1 addition & 1 deletion packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ export function inspectHooksOfFiber(
fiber: Fiber,
currentDispatcher: ?CurrentDispatcherRef,
includeHooksSource?: boolean = false,
) {
): HooksTree {
// DevTools will pass the current renderer's injected dispatcher.
// Other apps might compile debug hooks as part of their app though.
if (currentDispatcher == null) {
Expand Down
8 changes: 5 additions & 3 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ export function clearContainer(container: Container): void {

export const supportsHydration = true;

export function isHydratableResource(type: string, props: Props) {
export function isHydratableResource(type: string, props: Props): boolean {
return (
type === 'link' &&
typeof (props: any).precedence === 'string' &&
Expand Down Expand Up @@ -723,11 +723,13 @@ export function canHydrateSuspenseInstance(
return ((instance: any): SuspenseInstance);
}

export function isSuspenseInstancePending(instance: SuspenseInstance) {
export function isSuspenseInstancePending(instance: SuspenseInstance): boolean {
return instance.data === SUSPENSE_PENDING_START_DATA;
}

export function isSuspenseInstanceFallback(instance: SuspenseInstance) {
export function isSuspenseInstanceFallback(
instance: SuspenseInstance,
): boolean {
return instance.data === SUSPENSE_FALLBACK_START_DATA;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/inputValueTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function track(node: ElementWithValueTracker) {
node._valueTracker = trackValueOnNode(node);
}

export function updateValueIfChanged(node: ElementWithValueTracker) {
export function updateValueIfChanged(node: ElementWithValueTracker): boolean {
if (!node) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/events/checkPassiveEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import {canUseDOM} from 'shared/ExecutionEnvironment';

export let passiveBrowserEventsSupported = false;
export let passiveBrowserEventsSupported: boolean = false;

// Check if browser support events with passive listeners
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/shared/DOMProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export type PropertyInfo = {
export const ATTRIBUTE_NAME_START_CHAR =
':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
/* eslint-enable max-len */
export const ATTRIBUTE_NAME_CHAR =
export const ATTRIBUTE_NAME_CHAR: string =
ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';

export const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
export const VALID_ATTRIBUTE_NAME_REGEX: RegExp = new RegExp(
'^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
);

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/shared/isCustomComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

function isCustomComponent(tagName: string, props: Object) {
function isCustomComponent(tagName: string, props: Object): boolean {
if (tagName.indexOf('-') === -1) {
return typeof props.is === 'string';
}
Expand Down
28 changes: 14 additions & 14 deletions packages/react-is/src/ReactIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ let hasWarnedAboutDeprecatedIsAsyncMode = false;
let hasWarnedAboutDeprecatedIsConcurrentMode = false;

// AsyncMode should be deprecated
export function isAsyncMode(object: any) {
export function isAsyncMode(object: any): boolean {
if (__DEV__) {
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
hasWarnedAboutDeprecatedIsAsyncMode = true;
Expand All @@ -95,7 +95,7 @@ export function isAsyncMode(object: any) {
}
return false;
}
export function isConcurrentMode(object: any) {
export function isConcurrentMode(object: any): boolean {
if (__DEV__) {
if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
hasWarnedAboutDeprecatedIsConcurrentMode = true;
Expand All @@ -108,43 +108,43 @@ export function isConcurrentMode(object: any) {
}
return false;
}
export function isContextConsumer(object: any) {
export function isContextConsumer(object: any): boolean {
return typeOf(object) === REACT_CONTEXT_TYPE;
}
export function isContextProvider(object: any) {
export function isContextProvider(object: any): boolean {
return typeOf(object) === REACT_PROVIDER_TYPE;
}
export function isElement(object: any) {
export function isElement(object: any): boolean {
return (
typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE
);
}
export function isForwardRef(object: any) {
export function isForwardRef(object: any): boolean {
return typeOf(object) === REACT_FORWARD_REF_TYPE;
}
export function isFragment(object: any) {
export function isFragment(object: any): boolean {
return typeOf(object) === REACT_FRAGMENT_TYPE;
}
export function isLazy(object: any) {
export function isLazy(object: any): boolean {
return typeOf(object) === REACT_LAZY_TYPE;
}
export function isMemo(object: any) {
export function isMemo(object: any): boolean {
return typeOf(object) === REACT_MEMO_TYPE;
}
export function isPortal(object: any) {
export function isPortal(object: any): boolean {
return typeOf(object) === REACT_PORTAL_TYPE;
}
export function isProfiler(object: any) {
export function isProfiler(object: any): boolean {
return typeOf(object) === REACT_PROFILER_TYPE;
}
export function isStrictMode(object: any) {
export function isStrictMode(object: any): boolean {
return typeOf(object) === REACT_STRICT_MODE_TYPE;
}
export function isSuspense(object: any) {
export function isSuspense(object: any): boolean {
return typeOf(object) === REACT_SUSPENSE_TYPE;
}
export function isSuspenseList(object: any) {
export function isSuspenseList(object: any): boolean {
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactCurrentFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function setIsRendering(rendering: boolean) {
}
}

export function getIsRendering() {
export function getIsRendering(): void | boolean {
if (__DEV__) {
return isRendering;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactEventPriorities.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function getCurrentUpdatePriority(): EventPriority {
: (getCurrentUpdatePriority_old(): any);
}

export function setCurrentUpdatePriority(priority: EventPriority) {
export function setCurrentUpdatePriority(priority: EventPriority): void {
return enableNewReconciler
? setCurrentUpdatePriority_new((priority: any))
: setCurrentUpdatePriority_old((priority: any));
Expand Down
7 changes: 5 additions & 2 deletions packages/react-reconciler/src/ReactFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function shouldConstruct(Component: Function) {
return !!(prototype && prototype.isReactComponent);
}

export function isSimpleFunctionComponent(type: any) {
export function isSimpleFunctionComponent(type: any): boolean {
return (
typeof type === 'function' &&
!shouldConstruct(type) &&
Expand Down Expand Up @@ -355,7 +355,10 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
}

// Used to reuse a Fiber for a second pass.
export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
export function resetWorkInProgress(
workInProgress: Fiber,
renderLanes: Lanes,
): Fiber {
// This resets the Fiber to what createFiber or createWorkInProgress would
// have set the values to before during the first pass. Ideally this wouldn't
// be necessary but unfortunately many code paths reads from the workInProgress
Expand Down
7 changes: 5 additions & 2 deletions packages/react-reconciler/src/ReactFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function shouldConstruct(Component: Function) {
return !!(prototype && prototype.isReactComponent);
}

export function isSimpleFunctionComponent(type: any) {
export function isSimpleFunctionComponent(type: any): boolean {
return (
typeof type === 'function' &&
!shouldConstruct(type) &&
Expand Down Expand Up @@ -355,7 +355,10 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
}

// Used to reuse a Fiber for a second pass.
export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
export function resetWorkInProgress(
workInProgress: Fiber,
renderLanes: Lanes,
): Fiber {
// This resets the Fiber to what createFiber or createWorkInProgress would
// have set the values to before during the first pass. Ideally this wouldn't
// be necessary but unfortunately many code paths reads from the workInProgress
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberAct.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {warnsIfNotActing} from './ReactFiberHostConfig';

const {ReactCurrentActQueue} = ReactSharedInternals;

export function isLegacyActEnvironment(fiber: Fiber) {
export function isLegacyActEnvironment(fiber: Fiber): boolean {
if (__DEV__) {
// Legacy mode. We preserve the behavior of React 17's act. It assumes an
// act environment whenever `jest` is defined, but you can still turn off
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberAct.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {warnsIfNotActing} from './ReactFiberHostConfig';

const {ReactCurrentActQueue} = ReactSharedInternals;

export function isLegacyActEnvironment(fiber: Fiber) {
export function isLegacyActEnvironment(fiber: Fiber): boolean {
if (__DEV__) {
// Legacy mode. We preserve the behavior of React 17's act. It assumes an
// act environment whenever `jest` is defined, but you can still turn off
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ let didWarnAboutModulePatternComponent;
let didWarnAboutContextTypeOnFunctionComponent;
let didWarnAboutGetDerivedStateOnFunctionComponent;
let didWarnAboutFunctionRefs;
export let didWarnAboutReassigningProps;
export let didWarnAboutReassigningProps: boolean;
let didWarnAboutRevealOrder;
let didWarnAboutTailOptions;
let didWarnAboutDefaultPropsOnFunctionComponent;
Expand Down Expand Up @@ -3479,7 +3479,7 @@ export function markWorkInProgressReceivedUpdate() {
didReceiveUpdate = true;
}

export function checkIfWorkInProgressReceivedUpdate() {
export function checkIfWorkInProgressReceivedUpdate(): boolean {
return didReceiveUpdate;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ let didWarnAboutModulePatternComponent;
let didWarnAboutContextTypeOnFunctionComponent;
let didWarnAboutGetDerivedStateOnFunctionComponent;
let didWarnAboutFunctionRefs;
export let didWarnAboutReassigningProps;
export let didWarnAboutReassigningProps: boolean;
let didWarnAboutRevealOrder;
let didWarnAboutTailOptions;
let didWarnAboutDefaultPropsOnFunctionComponent;
Expand Down Expand Up @@ -3479,7 +3479,7 @@ export function markWorkInProgressReceivedUpdate() {
didReceiveUpdate = true;
}

export function checkIfWorkInProgressReceivedUpdate() {
export function checkIfWorkInProgressReceivedUpdate(): boolean {
return didReceiveUpdate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ let hasForceUpdate = false;

let didWarnUpdateInsideUpdate;
let currentlyProcessingQueue;
export let resetCurrentlyProcessingQueue;
export let resetCurrentlyProcessingQueue: () => void;
if (__DEV__) {
didWarnUpdateInsideUpdate = false;
currentlyProcessingQueue = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ let hasForceUpdate = false;

let didWarnUpdateInsideUpdate;
let currentlyProcessingQueue;
export let resetCurrentlyProcessingQueue;
export let resetCurrentlyProcessingQueue: () => void;
if (__DEV__) {
didWarnUpdateInsideUpdate = false;
currentlyProcessingQueue = null;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ let shouldFireAfterActiveInstanceBlur: boolean = false;
export function commitBeforeMutationEffects(
root: FiberRoot,
firstChild: Fiber,
) {
): boolean {
focusedInstanceHandle = prepareForCommit(root.containerInfo);

nextEffect = firstChild;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ let shouldFireAfterActiveInstanceBlur: boolean = false;
export function commitBeforeMutationEffects(
root: FiberRoot,
firstChild: Fiber,
) {
): boolean {
focusedInstanceHandle = prepareForCommit(root.containerInfo);

nextEffect = firstChild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ export function popHiddenContext(fiber: Fiber): void {
pop(prevRenderLanesStackCursor, fiber);
}

export function isCurrentTreeHidden() {
export function isCurrentTreeHidden(): boolean {
return currentTreeHiddenStackCursor.current !== null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ export function popHiddenContext(fiber: Fiber): void {
pop(prevRenderLanesStackCursor, fiber);
}

export function isCurrentTreeHidden() {
export function isCurrentTreeHidden(): boolean {
return currentTreeHiddenStackCursor.current !== null;
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export function renderWithHooks<Props, SecondArg>(
return children;
}

export function checkDidRenderIdHook() {
export function checkDidRenderIdHook(): boolean {
// This should be called immediately after every renderWithHooks call.
// Conceptually, it's part of the return value of renderWithHooks; it's only a
// separate function to avoid using an array tuple.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export function renderWithHooks<Props, SecondArg>(
return children;
}

export function checkDidRenderIdHook() {
export function checkDidRenderIdHook(): boolean {
// This should be called immediately after every renderWithHooks call.
// Conceptually, it's part of the return value of renderWithHooks; it's only a
// separate function to avoid using an array tuple.
Expand Down
23 changes: 15 additions & 8 deletions packages/react-reconciler/src/ReactFiberHotReloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @flow
*/

import type {Fiber} from './ReactInternalTypes';
import type {ReactElement} from '../../shared/ReactElementType';
import type {Instance} from './ReactFiberHostConfig';
import type {FiberRoot} from './ReactInternalTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
Expand Down Expand Up @@ -58,9 +60,9 @@ export type FindHostInstancesForRefresh = (
families: Array<Family>,
) => Set<Instance>;

export const setRefreshHandler = enableNewReconciler
? setRefreshHandler_new
: setRefreshHandler_old;
export const setRefreshHandler: (
handler: RefreshHandler | null,
) => void = enableNewReconciler ? setRefreshHandler_new : setRefreshHandler_old;
export const resolveFunctionForHotReloading = enableNewReconciler
? resolveFunctionForHotReloading_new
: resolveFunctionForHotReloading_old;
Expand All @@ -70,18 +72,23 @@ export const resolveClassForHotReloading = enableNewReconciler
export const resolveForwardRefForHotReloading = enableNewReconciler
? resolveForwardRefForHotReloading_new
: resolveForwardRefForHotReloading_old;
export const isCompatibleFamilyForHotReloading = enableNewReconciler
export const isCompatibleFamilyForHotReloading: (
fiber: Fiber,
element: ReactElement,
) => boolean = enableNewReconciler
? isCompatibleFamilyForHotReloading_new
: isCompatibleFamilyForHotReloading_old;
export const markFailedErrorBoundaryForHotReloading = enableNewReconciler
export const markFailedErrorBoundaryForHotReloading: (
fiber: Fiber,
) => void = enableNewReconciler
? markFailedErrorBoundaryForHotReloading_new
: markFailedErrorBoundaryForHotReloading_old;
export const scheduleRefresh = enableNewReconciler
export const scheduleRefresh: ScheduleRefresh = enableNewReconciler
? scheduleRefresh_new
: scheduleRefresh_old;
export const scheduleRoot = enableNewReconciler
export const scheduleRoot: ScheduleRoot = enableNewReconciler
? scheduleRoot_new
: scheduleRoot_old;
export const findHostInstancesForRefresh = enableNewReconciler
export const findHostInstancesForRefresh: FindHostInstancesForRefresh = enableNewReconciler
? findHostInstancesForRefresh_new
: findHostInstancesForRefresh_old;
Loading

0 comments on commit 3d9bba3

Please sign in to comment.