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 1ca3b1a
Show file tree
Hide file tree
Showing 39 changed files with 139 additions and 108 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
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
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
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
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
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;
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function markDidThrowWhileHydratingDEV() {
}
}

export function didSuspendOrErrorWhileHydratingDEV() {
export function didSuspendOrErrorWhileHydratingDEV(): boolean {
if (__DEV__) {
return didSuspendOrErrorDEV;
}
Expand Down Expand Up @@ -685,7 +685,7 @@ function popHydrationState(fiber: Fiber): boolean {
return true;
}

function hasUnhydratedTailNodes() {
function hasUnhydratedTailNodes(): boolean {
return isHydrating && nextHydratableInstance !== null;
}

Expand Down
24 changes: 12 additions & 12 deletions packages/react-reconciler/src/ReactFiberLane.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export function markStarvedLanesAsExpired(

// This returns the highest priority pending lanes regardless of whether they
// are suspended.
export function getHighestPriorityPendingLanes(root: FiberRoot) {
export function getHighestPriorityPendingLanes(root: FiberRoot): Lanes {
return getHighestPriorityLanes(root.pendingLanes);
}

Expand All @@ -458,25 +458,25 @@ export function getLanesToRetrySynchronouslyOnError(
return NoLanes;
}

export function includesSyncLane(lanes: Lanes) {
export function includesSyncLane(lanes: Lanes): boolean {
return (lanes & SyncLane) !== NoLanes;
}

export function includesNonIdleWork(lanes: Lanes) {
export function includesNonIdleWork(lanes: Lanes): boolean {
return (lanes & NonIdleLanes) !== NoLanes;
}
export function includesOnlyRetries(lanes: Lanes) {
export function includesOnlyRetries(lanes: Lanes): boolean {
return (lanes & RetryLanes) === lanes;
}
export function includesOnlyNonUrgentLanes(lanes: Lanes) {
export function includesOnlyNonUrgentLanes(lanes: Lanes): boolean {
const UrgentLanes = SyncLane | InputContinuousLane | DefaultLane;
return (lanes & UrgentLanes) === NoLanes;
}
export function includesOnlyTransitions(lanes: Lanes) {
export function includesOnlyTransitions(lanes: Lanes): boolean {
return (lanes & TransitionLanes) === lanes;
}

export function includesBlockingLane(root: FiberRoot, lanes: Lanes) {
export function includesBlockingLane(root: FiberRoot, lanes: Lanes): boolean {
if (
allowConcurrentByDefault &&
(root.current.mode & ConcurrentUpdatesByDefaultMode) !== NoMode
Expand All @@ -492,13 +492,13 @@ export function includesBlockingLane(root: FiberRoot, lanes: Lanes) {
return (lanes & SyncDefaultLanes) !== NoLanes;
}

export function includesExpiredLane(root: FiberRoot, lanes: Lanes) {
export function includesExpiredLane(root: FiberRoot, lanes: Lanes): boolean {
// This is a separate check from includesBlockingLane because a lane can
// expire after a render has already started.
return (lanes & root.expiredLanes) !== NoLanes;
}

export function isTransitionLane(lane: Lane) {
export function isTransitionLane(lane: Lane): boolean {
return (lane & TransitionLanes) !== NoLanes;
}

Expand Down Expand Up @@ -543,11 +543,11 @@ function laneToIndex(lane: Lane) {
return pickArbitraryLaneIndex(lane);
}

export function includesSomeLane(a: Lanes | Lane, b: Lanes | Lane) {
export function includesSomeLane(a: Lanes | Lane, b: Lanes | Lane): boolean {
return (a & b) !== NoLanes;
}

export function isSubsetOfLanes(set: Lanes, subset: Lanes | Lane) {
export function isSubsetOfLanes(set: Lanes, subset: Lanes | Lane): boolean {
return (set & subset) === subset;
}

Expand All @@ -569,7 +569,7 @@ export function laneToLanes(lane: Lane): Lanes {
return lane;
}

export function higherPriorityLane(a: Lane, b: Lane) {
export function higherPriorityLane(a: Lane, b: Lane): Lane {
// This works because the bit ranges decrease in priority as you go left.
return a !== NoLane && a < b ? a : b;
}
Expand Down
Loading

0 comments on commit 1ca3b1a

Please sign in to comment.