Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'ReportActionItem.js' component to TypeScript #34487

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
1c13e82
ref: wip
kubabutkiewicz Jan 12, 2024
b257c3e
Merge branch 'Expensify:main' into main
kubabutkiewicz Jan 12, 2024
457ad4c
Revert "ref: wip"
kubabutkiewicz Jan 12, 2024
0882361
ref: wip
kubabutkiewicz Jan 12, 2024
6b4fe34
Merge branch 'Expensify:main' into main
kubabutkiewicz Jan 12, 2024
10eefa0
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 12, 2024
36f3081
ref: wip
kubabutkiewicz Jan 12, 2024
4074619
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 15, 2024
d3a184a
fix: wip
kubabutkiewicz Jan 16, 2024
f291344
fix: wip
kubabutkiewicz Jan 16, 2024
f8b01bf
fix: wip
kubabutkiewicz Jan 16, 2024
ff4c7a8
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 16, 2024
c4df84d
fix: last types problems
kubabutkiewicz Jan 16, 2024
8b88e30
fix: remove unnecessary comment
kubabutkiewicz Jan 16, 2024
e5c32ee
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 17, 2024
62c72a7
fix: typecheck
kubabutkiewicz Jan 17, 2024
e1deff2
fix: resolve comments
kubabutkiewicz Jan 17, 2024
d54eef9
fix: types in OnyxKeys and migration files
kubabutkiewicz Jan 17, 2024
16e8c9d
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 18, 2024
e3bd929
fix :resolve conflicts
kubabutkiewicz Jan 18, 2024
8f599e5
fix: typecheck and lint
kubabutkiewicz Jan 18, 2024
fea6b71
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 19, 2024
8cf1b3e
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 29, 2024
36bbd18
fix: typecheck
kubabutkiewicz Jan 29, 2024
ad074de
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Jan 30, 2024
fcaaa64
fix: typecheck
kubabutkiewicz Jan 30, 2024
0162bc5
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 2, 2024
8a3b9c7
fix: typecheck
kubabutkiewicz Feb 2, 2024
7681001
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 5, 2024
49ffbf6
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 5, 2024
22a6ae7
fix: typecheck
kubabutkiewicz Feb 5, 2024
527f89e
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 7, 2024
021c4dd
fix: typecheck
kubabutkiewicz Feb 7, 2024
354040b
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 7, 2024
92b0c42
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 8, 2024
e45e14a
fix: resolve comment
kubabutkiewicz Feb 9, 2024
3b56527
fix: resolve comments
kubabutkiewicz Feb 9, 2024
f8e68c1
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 13, 2024
f154a6b
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 14, 2024
0f0b14f
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 14, 2024
280d3b8
fix: resolve comments
kubabutkiewicz Feb 14, 2024
4eb10ac
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 15, 2024
1d04836
fix: conflicts and comments
kubabutkiewicz Feb 15, 2024
cc551c7
fix: removed unnecessary type
kubabutkiewicz Feb 15, 2024
bdf7030
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 21, 2024
98ac18b
fix: typecheck
kubabutkiewicz Feb 21, 2024
4f53fac
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 22, 2024
596c8fd
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 23, 2024
35f02e8
Merge branch 'main' into ts-migration/ReportActionItem2/component
kubabutkiewicz Feb 26, 2024
a86f85f
fix: typecheck
kubabutkiewicz Feb 26, 2024
bf1d2d2
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 26, 2024
2690b57
fix: typecheck
kubabutkiewicz Feb 26, 2024
075bf1a
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 27, 2024
937359d
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Feb 28, 2024
ad3c1fa
fix: lint
kubabutkiewicz Feb 28, 2024
0459df0
fix: lint
kubabutkiewicz Feb 28, 2024
ff903d3
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Mar 4, 2024
02d23b1
fix: resolve comments
kubabutkiewicz Mar 4, 2024
c8357cd
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Mar 5, 2024
429a111
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into t…
kubabutkiewicz Mar 7, 2024
329c724
fix: typecheck
kubabutkiewicz Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type CONST from './CONST';
import type * as FormTypes from './types/form';
Expand Down Expand Up @@ -589,7 +589,7 @@ type OnyxFormDraftKey = keyof OnyxFormDraftValuesMapping;
type OnyxValueKey = keyof OnyxValuesMapping;

type OnyxKey = OnyxValueKey | OnyxCollectionKey | OnyxFormKey | OnyxFormDraftKey;
type OnyxValue<TOnyxKey extends OnyxKey> = OnyxEntry<OnyxValues[TOnyxKey]>;
type OnyxValue<TOnyxKey extends OnyxKey> = TOnyxKey extends keyof OnyxCollectionValuesMapping ? OnyxCollection<OnyxValues[TOnyxKey]> : OnyxEntry<OnyxValues[TOnyxKey]>;

type MissingOnyxKeysError = `Error: Types don't match, OnyxKey type is missing: ${Exclude<AllOnyxKeys, OnyxKey>}`;
/** If this type errors, it means that the `OnyxKey` type is missing some keys. */
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function Button(
accessibilityLabel = '',
...rest
}: ButtonProps,
ref: ForwardedRef<View>,
ref: ForwardedRef<View | HTMLDivElement>,
) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down
11 changes: 6 additions & 5 deletions src/components/FloatingActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {ForwardedRef} from 'react';
import React, {forwardRef, useEffect, useRef} from 'react';
import type {GestureResponderEvent, Role} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {GestureResponderEvent, Role, Text} from 'react-native';
import {Platform, View} from 'react-native';
import Animated, {createAnimatedPropAdapter, Easing, interpolateColor, processColor, useAnimatedProps, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import Svg, {Path} from 'react-native-svg';
Expand Down Expand Up @@ -58,12 +59,12 @@ type FloatingActionButtonProps = {
role: Role;
};

function FloatingActionButton({onPress, isActive, accessibilityLabel, role}: FloatingActionButtonProps, ref: ForwardedRef<HTMLDivElement | View>) {
function FloatingActionButton({onPress, isActive, accessibilityLabel, role}: FloatingActionButtonProps, ref: ForwardedRef<HTMLDivElement | View | Text>) {
const {success, buttonDefaultBG, textLight, textDark} = useTheme();
const styles = useThemeStyles();
const borderRadius = styles.floatingActionButton.borderRadius;
const {translate} = useLocalize();
const fabPressable = useRef<HTMLDivElement | View | null>(null);
const fabPressable = useRef<HTMLDivElement | View | Text | null>(null);
const sharedValue = useSharedValue(isActive ? 1 : 0);
const buttonRef = ref;

Expand Down Expand Up @@ -112,9 +113,9 @@ function FloatingActionButton({onPress, isActive, accessibilityLabel, role}: Flo
<View style={styles.bottomTabBarItem}>
<AnimatedPressable
ref={(el) => {
fabPressable.current = el;
fabPressable.current = el ?? null;
if (buttonRef && 'current' in buttonRef) {
buttonRef.current = el;
buttonRef.current = el ?? null;
}
}}
accessibilityLabel={accessibilityLabel}
Expand Down
12 changes: 6 additions & 6 deletions src/components/KYCWall/BaseKYCWall.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {Dimensions} from 'react-native';
import type {EmitterSubscription, GestureResponderEvent} from 'react-native';
import type {EmitterSubscription, GestureResponderEvent, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import AddPaymentMethodMenu from '@components/AddPaymentMethodMenu';
Expand Down Expand Up @@ -69,8 +69,8 @@ function KYCWall({
walletTerms,
shouldShowPersonalBankAccountOption = false,
}: BaseKYCWallProps) {
const anchorRef = useRef<HTMLDivElement>(null);
const transferBalanceButtonRef = useRef<HTMLElement | null>(null);
const anchorRef = useRef<HTMLDivElement | View | null>(null);
const transferBalanceButtonRef = useRef<HTMLDivElement | View | null>(null);

const [shouldShowAddPaymentMenu, setShouldShowAddPaymentMenu] = useState(false);

Expand Down Expand Up @@ -111,7 +111,7 @@ function KYCWall({
return;
}

const buttonPosition = getClickedTargetLocation(transferBalanceButtonRef.current);
const buttonPosition = getClickedTargetLocation(transferBalanceButtonRef.current as HTMLDivElement);
const position = getAnchorPosition(buttonPosition);

setPositionAddPaymentMenu(position);
Expand Down Expand Up @@ -162,7 +162,7 @@ function KYCWall({
}

// Use event target as fallback if anchorRef is null for safety
const targetElement = anchorRef.current ?? (event?.currentTarget as HTMLElement);
const targetElement = anchorRef.current ?? (event?.currentTarget as HTMLDivElement);

transferBalanceButtonRef.current = targetElement;

Expand All @@ -181,7 +181,7 @@ function KYCWall({
return;
}

const clickedElementLocation = getClickedTargetLocation(targetElement);
const clickedElementLocation = getClickedTargetLocation(targetElement as HTMLDivElement);
const position = getAnchorPosition(clickedElementLocation);

setPositionAddPaymentMenu(position);
Expand Down
6 changes: 4 additions & 2 deletions src/components/OnyxProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import createOnyxContext from './createOnyxContext';
const [withNetwork, NetworkProvider, NetworkContext] = createOnyxContext(ONYXKEYS.NETWORK);
const [withPersonalDetails, PersonalDetailsProvider, , usePersonalDetails] = createOnyxContext(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [withCurrentDate, CurrentDateProvider] = createOnyxContext(ONYXKEYS.CURRENT_DATE);
const [withReportActionsDrafts, ReportActionsDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS);
const [withBlockedFromConcierge, BlockedFromConciergeProvider] = createOnyxContext(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE);
const [withReportActionsDrafts, ReportActionsDraftsProvider, , useReportActionsDrafts] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS);
const [withBlockedFromConcierge, BlockedFromConciergeProvider, , useBlockedFromConcierge] = createOnyxContext(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE);
const [withBetas, BetasProvider, BetasContext, useBetas] = createOnyxContext(ONYXKEYS.BETAS);
const [withReportCommentDrafts, ReportCommentDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
const [withPreferredTheme, PreferredThemeProvider, PreferredThemeContext] = createOnyxContext(ONYXKEYS.PREFERRED_THEME);
Expand Down Expand Up @@ -66,5 +66,7 @@ export {
useFrequentlyUsedEmojis,
withPreferredEmojiSkinTone,
PreferredEmojiSkinToneContext,
useBlockedFromConcierge,
useReportActionsDrafts,
useSession,
};
5 changes: 3 additions & 2 deletions src/components/Popover/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {RefObject} from 'react';
import type {View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {Text, View} from 'react-native';
import type {PopoverAnchorPosition} from '@components/Modal/types';
import type BaseModalProps from '@components/Modal/types';
import type {WindowDimensionsProps} from '@components/withWindowDimensions/types';
Expand All @@ -20,7 +21,7 @@ type PopoverProps = BaseModalProps &
anchorAlignment?: AnchorAlignment;

/** The anchor ref of the popover */
anchorRef: RefObject<View | HTMLDivElement>;
anchorRef: RefObject<View | HTMLDivElement | Text>;

/** Whether disable the animations */
disableAnimation?: boolean;
Expand Down
7 changes: 4 additions & 3 deletions src/components/PopoverProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {RefObject} from 'react';
import React, {createContext, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {Text, View} from 'react-native';
import type {AnchorRef, PopoverContextProps, PopoverContextValue} from './types';

const PopoverContext = createContext<PopoverContextValue>({
Expand All @@ -10,7 +11,7 @@ const PopoverContext = createContext<PopoverContextValue>({
isOpen: false,
});

function elementContains(ref: RefObject<View | HTMLElement> | undefined, target: EventTarget | null) {
function elementContains(ref: RefObject<View | HTMLElement | Text> | undefined, target: EventTarget | null) {
if (ref?.current && 'contains' in ref.current && ref?.current?.contains(target as Node)) {
return true;
}
Expand All @@ -21,7 +22,7 @@ function PopoverContextProvider(props: PopoverContextProps) {
const [isOpen, setIsOpen] = useState(false);
const activePopoverRef = useRef<AnchorRef | null>(null);

const closePopover = useCallback((anchorRef?: RefObject<View | HTMLElement>): boolean => {
const closePopover = useCallback((anchorRef?: RefObject<View | HTMLElement | Text>): boolean => {
if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) {
return false;
}
Expand Down
11 changes: 6 additions & 5 deletions src/components/PopoverProvider/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {ReactNode, RefObject} from 'react';
import type {View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {Text, View} from 'react-native';

type PopoverContextProps = {
children: ReactNode;
Expand All @@ -8,14 +9,14 @@ type PopoverContextProps = {
type PopoverContextValue = {
onOpen?: (popoverParams: AnchorRef) => void;
popover?: AnchorRef | Record<string, never> | null;
close: (anchorRef?: RefObject<View | HTMLDivElement>) => void;
close: (anchorRef?: RefObject<View | HTMLDivElement | Text>) => void;
isOpen: boolean;
};

type AnchorRef = {
ref: RefObject<View | HTMLDivElement>;
close: (anchorRef?: RefObject<View | HTMLDivElement>) => void;
anchorRef: RefObject<View | HTMLDivElement>;
ref: RefObject<View | HTMLDivElement | Text>;
close: (anchorRef?: RefObject<View | HTMLDivElement | Text>) => void;
anchorRef: RefObject<View | HTMLDivElement | Text>;
};

export type {PopoverContextProps, PopoverContextValue, AnchorRef};
5 changes: 3 additions & 2 deletions src/components/PopoverWithoutOverlay/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {RefObject} from 'react';
import type {View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {Text, View} from 'react-native';
import type BaseModalProps from '@components/Modal/types';
import type ChildrenProps from '@src/types/utils/ChildrenProps';

Expand All @@ -14,7 +15,7 @@ type PopoverWithoutOverlayProps = ChildrenProps &
};

/** The anchor ref of the popover */
anchorRef: RefObject<View | HTMLDivElement>;
anchorRef: RefObject<View | HTMLDivElement | Text>;

/** A react-native-animatable animation timing for the modal display animation */
animationInTiming?: number;
Expand Down
5 changes: 3 additions & 2 deletions src/components/Pressable/GenericPressable/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {ElementRef, ForwardedRef, RefObject} from 'react';
import type {GestureResponderEvent, HostComponent, PressableStateCallbackType, PressableProps as RNPressableProps, StyleProp, View, ViewStyle} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {GestureResponderEvent, HostComponent, PressableStateCallbackType, PressableProps as RNPressableProps, Text as RNText, StyleProp, View, ViewStyle} from 'react-native';
import type {ValueOf} from 'type-fest';
import type {Shortcut} from '@libs/KeyboardShortcut';
import type CONST from '@src/CONST';
Expand Down Expand Up @@ -138,7 +139,7 @@ type PressableProps = RNPressableProps &
noDragArea?: boolean;
};

type PressableRef = ForwardedRef<HTMLDivElement | View>;
type PressableRef = ForwardedRef<HTMLDivElement | View | RNText | undefined>;

export default PressableProps;
export type {PressableRef};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {ParsableStyle} from '@styles/utils/types';

type PressableWithSecondaryInteractionProps = PressableWithFeedbackProps & {
/** The function that should be called when this pressable is pressed */
onPress: (event?: GestureResponderEvent) => void;
onPress?: (event?: GestureResponderEvent) => void;

/** The function that should be called when this pressable is pressedIn */
onPressIn?: (event?: GestureResponderEvent) => void;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Reactions/ReportActionItemEmojiReactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ReportActionItemEmojiReactionsProps = WithCurrentUserPersonalDetailsProps &
emojiReactions: OnyxEntry<ReportActionReactions>;

/** The user's preferred locale. */
preferredLocale: OnyxEntry<Locale>;
preferredLocale?: OnyxEntry<Locale>;

/** The report action that these reactions are for */
reportAction: ReportAction;
Expand Down Expand Up @@ -155,7 +155,7 @@ function ReportActionItemEmojiReactions({
shouldDisableOpacity={!!reportAction.pendingAction}
>
<EmojiReactionBubble
ref={(ref) => (popoverReactionListAnchors.current[reaction.reactionEmojiName] = ref)}
ref={(ref) => (popoverReactionListAnchors.current[reaction.reactionEmojiName] = ref ?? null)}
count={reaction.reactionCount}
emojiCodes={reaction.emojiCodes}
onPress={reaction.onPress}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Str from 'expensify-common/lib/str';
import React, {useMemo} from 'react';
import type {StyleProp, TextStyle} from 'react-native';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
Expand All @@ -26,7 +27,7 @@ type MoneyReportViewProps = {
report: Report;

/** Policy that the report belongs to */
policy: Policy;
policy: OnyxEntry<Policy>;

/** Policy report fields */
policyReportFields: PolicyReportField[];
Expand Down
8 changes: 4 additions & 4 deletions src/components/createOnyxContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {ComponentType, ForwardedRef, ForwardRefExoticComponent, PropsWithou
import React, {createContext, forwardRef, useContext} from 'react';
import {withOnyx} from 'react-native-onyx';
import getComponentDisplayName from '@libs/getComponentDisplayName';
import type {OnyxKey, OnyxValue, OnyxValues} from '@src/ONYXKEYS';
import type {OnyxKey, OnyxValue} from '@src/ONYXKEYS';
import type ChildrenProps from '@src/types/utils/ChildrenProps';

// Provider types
Expand Down Expand Up @@ -32,11 +32,11 @@ type CreateOnyxContext<TOnyxKey extends OnyxKey> = [
WithOnyxKey<TOnyxKey>,
ComponentType<Omit<ProviderPropsWithOnyx<TOnyxKey>, TOnyxKey>>,
React.Context<OnyxValue<TOnyxKey>>,
() => OnyxValues[TOnyxKey],
() => NonNullable<OnyxValue<TOnyxKey>>,
];

export default <TOnyxKey extends OnyxKey>(onyxKeyName: TOnyxKey): CreateOnyxContext<TOnyxKey> => {
const Context = createContext<OnyxValue<TOnyxKey>>(null);
const Context = createContext<OnyxValue<TOnyxKey>>(null as OnyxValue<TOnyxKey>);
function Provider(props: ProviderPropsWithOnyx<TOnyxKey>): ReactNode {
return <Context.Provider value={props[onyxKeyName]}>{props.children}</Context.Provider>;
}
Expand Down Expand Up @@ -86,7 +86,7 @@ export default <TOnyxKey extends OnyxKey>(onyxKeyName: TOnyxKey): CreateOnyxCont
if (value === null) {
throw new Error(`useOnyxContext must be used within a OnyxProvider [key: ${onyxKeyName}]`);
}
return value;
return value as NonNullable<OnyxValue<TOnyxKey>>;
};

return [withOnyxKey, ProviderWithOnyx, Context, useOnyxContext];
Expand Down
16 changes: 10 additions & 6 deletions src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ function getFrequentlyUsedEmojis(newEmoji: Emoji | Emoji[]): FrequentlyUsedEmoji
/**
* Given an emoji item object, return an emoji code based on its type.
*/
const getEmojiCodeWithSkinColor = (item: Emoji, preferredSkinToneIndex: number): string => {
const getEmojiCodeWithSkinColor = (item: Emoji, preferredSkinToneIndex: OnyxEntry<string | number>): string | undefined => {
const {code, types} = item;
if (types?.[preferredSkinToneIndex]) {
if (!preferredSkinToneIndex) {
return;
}

if (typeof preferredSkinToneIndex === 'number' && types?.[preferredSkinToneIndex]) {
return types[preferredSkinToneIndex];
}

Expand Down Expand Up @@ -305,7 +309,7 @@ function getAddedEmojis(currentEmojis: Emoji[], formerEmojis: Emoji[]): Emoji[]
* Replace any emoji name in a text with the emoji icon.
* If we're on mobile, we also add a space after the emoji granted there's no text after it.
*/
function replaceEmojis(text: string, preferredSkinTone: number = CONST.EMOJI_DEFAULT_SKIN_TONE, lang: Locale = CONST.LOCALES.DEFAULT): ReplacedEmoji {
function replaceEmojis(text: string, preferredSkinTone: OnyxEntry<number | string> = CONST.EMOJI_DEFAULT_SKIN_TONE, lang: Locale = CONST.LOCALES.DEFAULT): ReplacedEmoji {
// emojisTrie is importing the emoji JSON file on the app starting and we want to avoid it
const emojisTrie = require('./EmojiTrie').default;

Expand Down Expand Up @@ -345,9 +349,9 @@ function replaceEmojis(text: string, preferredSkinTone: number = CONST.EMOJI_DEF

// Set the cursor to the end of the last replaced Emoji. Note that we position after
// the extra space, if we added one.
cursorPosition = newText.indexOf(emoji) + emojiReplacement.length;
cursorPosition = newText.indexOf(emoji) + (emojiReplacement?.length ?? 0);

newText = newText.replace(emoji, emojiReplacement);
newText = newText.replace(emoji, emojiReplacement ?? '');
}
}

Expand All @@ -369,7 +373,7 @@ function replaceEmojis(text: string, preferredSkinTone: number = CONST.EMOJI_DEF
/**
* Find all emojis in a text and replace them with their code.
*/
function replaceAndExtractEmojis(text: string, preferredSkinTone: number = CONST.EMOJI_DEFAULT_SKIN_TONE, lang: Locale = CONST.LOCALES.DEFAULT): ReplacedEmoji {
function replaceAndExtractEmojis(text: string, preferredSkinTone: OnyxEntry<number | string> = CONST.EMOJI_DEFAULT_SKIN_TONE, lang: Locale = CONST.LOCALES.DEFAULT): ReplacedEmoji {
const {text: convertedText = '', emojis = [], cursorPosition} = replaceEmojis(text, preferredSkinTone, lang);

return {
Expand Down
2 changes: 2 additions & 0 deletions src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,5 @@ export {
getMicroSecondOnyxErrorObject,
isReceiptError,
};

export type {OnyxDataWithErrors};
5 changes: 3 additions & 2 deletions src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {OnyxValue} from '@src/ONYXKEYS';
import type {OnyxEntry} from 'react-native-onyx';
import type {Report} from '@src/types/onyx';

export default function reportWithoutHasDraftSelector(report: OnyxValue<'report_'>) {
export default function reportWithoutHasDraftSelector(report: OnyxEntry<Report>) {
if (!report) {
return report;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ function hasRequestFromCurrentAccount(reportID: string, currentAccountID: number
* Checks if a given report action corresponds to an actionable mention whisper.
* @param reportAction
*/
function isActionableMentionWhisper(reportAction: OnyxEntry<ReportAction>): boolean {
function isActionableMentionWhisper(reportAction: OnyxEntry<ReportAction>): reportAction is ReportActionBase & OriginalMessageActionableMentionWhisper {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER;
}

Expand Down
6 changes: 3 additions & 3 deletions src/libs/calculateAnchorPosition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-restricted-imports */
import type {Text as RNText, View} from 'react-native';
import type {ValueOf} from 'type-fest';
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import CONST from '@src/CONST';
import type {AnchorPosition} from '@src/styles';

Expand All @@ -13,9 +13,9 @@ type AnchorOrigin = {
/**
* Gets the x,y position of the passed in component for the purpose of anchoring another component to it.
*/
export default function calculateAnchorPosition(anchorComponent: View | RNText, anchorOrigin?: AnchorOrigin): Promise<AnchorPosition> {
export default function calculateAnchorPosition(anchorComponent: ContextMenuAnchor, anchorOrigin?: AnchorOrigin): Promise<AnchorPosition> {
return new Promise((resolve) => {
if (!anchorComponent) {
if (!anchorComponent || !('measureInWindow' in anchorComponent)) {
resolve({horizontal: 0, vertical: 0});
return;
}
Expand Down
Loading
Loading