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

[ON HOLD Onyx PR #534] Fix Onyx typings across the project #40367

Closed
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
7 changes: 4 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"type-fest": "^4.10.2",
"typescript": "^5.3.2",
"typescript": "^5.4.5",
"wait-port": "^0.2.9",
"webpack": "^5.76.0",
"webpack-bundle-analyzer": "^4.5.0",
Expand Down
6 changes: 3 additions & 3 deletions src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useCallback, useEffect, useRef} from 'react';
import {View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import useStyleUtils from '@hooks/useStyleUtils';
Expand All @@ -12,7 +12,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {PersonalDetails, Policy, Report, ReportActions} from '@src/types/onyx';
import type {PersonalDetails, PersonalDetailsList, Policy, Report, ReportActions} from '@src/types/onyx';
import DisplayNames from './DisplayNames';
import MultipleAvatars from './MultipleAvatars';
import ParentNavigationSubtitle from './ParentNavigationSubtitle';
Expand All @@ -25,7 +25,7 @@ type AvatarWithDisplayNamePropsWithOnyx = {
parentReportActions: OnyxEntry<ReportActions>;

/** Personal details of all users */
personalDetails: OnyxCollection<PersonalDetails>;
personalDetails: OnyxEntry<PersonalDetailsList>;
};

type AvatarWithDisplayNameProps = AvatarWithDisplayNamePropsWithOnyx & {
Expand Down
2 changes: 1 addition & 1 deletion src/components/KeyboardAvoidingView/index.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import React from 'react';
import {KeyboardAvoidingView as KeyboardAvoidingViewComponent} from 'react-native';
import type KeyboardAvoidingViewProps from './types';
import type {KeyboardAvoidingViewProps} from './types';

function KeyboardAvoidingView(props: KeyboardAvoidingViewProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down
2 changes: 1 addition & 1 deletion src/components/KeyboardAvoidingView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import React from 'react';
import {View} from 'react-native';
import type KeyboardAvoidingViewProps from './types';
import type {KeyboardAvoidingViewProps} from './types';

function KeyboardAvoidingView(props: KeyboardAvoidingViewProps) {
const {behavior, contentContainerStyle, enabled, keyboardVerticalOffset, ...rest} = props;
Expand Down
5 changes: 3 additions & 2 deletions src/components/KeyboardAvoidingView/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {KeyboardAvoidingViewProps} from 'react-native';
import type {KeyboardAvoidingViewProps} from 'react-native';

export default KeyboardAvoidingViewProps;
// eslint-disable-next-line import/prefer-default-export
export type {KeyboardAvoidingViewProps};
21 changes: 11 additions & 10 deletions src/languages/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {ReportAction} from '@src/types/onyx';
import type {Unit} from '@src/types/onyx/Policy';
import type en from './en';
Expand Down Expand Up @@ -44,15 +45,15 @@ type LocalTimeParams = {
};

type EditActionParams = {
action: ReportAction | null;
action: OnyxEntry<ReportAction>;
};

type DeleteActionParams = {
action: ReportAction | null;
action: OnyxEntry<ReportAction>;
};

type DeleteConfirmationParams = {
action: ReportAction | null;
action: OnyxEntry<ReportAction>;
};

type BeginningOfChatHistoryDomainRoomPartOneParams = {
Expand Down Expand Up @@ -303,11 +304,11 @@ type DistanceRateOperationsParams = {count: number};
type ReimbursementRateParams = {unit: Unit};

export type {
AdminCanceledRequestParams,
ApprovedAmountParams,
AddressLineParams,
AdminCanceledRequestParams,
AlreadySignedInParams,
AmountEachParams,
ApprovedAmountParams,
BeginningOfChatHistoryAdminRoomPartOneParams,
BeginningOfChatHistoryAnnounceRoomPartOneParams,
BeginningOfChatHistoryAnnounceRoomPartTwo,
Expand All @@ -328,8 +329,10 @@ export type {
FormattedMaxLengthParams,
GoBackMessageParams,
GoToRoomParams,
HeldRequestParams,
InstantSummaryParams,
LocalTimeParams,
LogSizeParams,
LoggedInAsParams,
ManagerApprovedAmountParams,
ManagerApprovedParams,
Expand All @@ -344,11 +347,13 @@ export type {
PaidElsewhereWithAmountParams,
PaidWithExpensifyWithAmountParams,
ParentNavigationSummaryParams,
PaySomeoneParams,
PayerOwesAmountParams,
PayerOwesParams,
PayerPaidAmountParams,
PayerPaidParams,
PayerSettledParams,
ReimbursementRateParams,
RemovedTheRequestParams,
RenamedRoomActionParams,
ReportArchiveReasonsClosedParams,
Expand Down Expand Up @@ -380,6 +385,7 @@ export type {
UntilTimeParams,
UpdatedTheDistanceParams,
UpdatedTheRequestParams,
UsePlusButtonParams,
UserIsAlreadyMemberParams,
ViolationsAutoReportedRejectedExpenseParams,
ViolationsCashExpenseWithNoReceiptParams,
Expand All @@ -397,14 +403,9 @@ export type {
ViolationsTaxOutOfPolicyParams,
WaitingOnBankAccountParams,
WalletProgramParams,
UsePlusButtonParams,
WeSentYouMagicSignInLinkParams,
WelcomeEnterMagicCodeParams,
WelcomeNoteParams,
WelcomeToRoomParams,
ZipCodeExampleFormatParams,
LogSizeParams,
HeldRequestParams,
PaySomeoneParams,
ReimbursementRateParams,
};
2 changes: 1 addition & 1 deletion src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function suggestEmojis(text: string, lang: Locale, limit: number = CONST.AUTO_CO
/**
* Retrieve preferredSkinTone as Number to prevent legacy 'default' String value
*/
const getPreferredSkinToneIndex = (value: string | number | null): number => {
const getPreferredSkinToneIndex = (value: OnyxEntry<string | number>): number => {
if (value !== null && Number.isInteger(Number(value))) {
return Number(value);
}
Expand Down
21 changes: 11 additions & 10 deletions src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mapValues from 'lodash/mapValues';
import type {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import type {TranslationFlatObject, TranslationPaths} from '@src/languages/types';
import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon';
Expand Down Expand Up @@ -61,7 +62,7 @@ type OnyxDataWithErrors = {
errors?: Errors | null;
};

function getLatestErrorMessage<TOnyxData extends OnyxDataWithErrors>(onyxData: TOnyxData | null): Localize.MaybePhraseKey {
function getLatestErrorMessage<TOnyxData extends OnyxDataWithErrors>(onyxData: OnyxEntry<TOnyxData>): Localize.MaybePhraseKey {
const errors = onyxData?.errors ?? {};

if (Object.keys(errors).length === 0) {
Expand All @@ -72,8 +73,8 @@ function getLatestErrorMessage<TOnyxData extends OnyxDataWithErrors>(onyxData: T
return getErrorMessageWithTranslationData(errors[key]);
}

function getLatestErrorMessageField<TOnyxData extends OnyxDataWithErrors>(onyxData: TOnyxData): Errors {
const errors = onyxData.errors ?? {};
function getLatestErrorMessageField<TOnyxData extends OnyxDataWithErrors>(onyxData: OnyxEntry<TOnyxData>): Errors {
const errors = onyxData?.errors ?? {};

if (Object.keys(errors).length === 0) {
return {};
Expand All @@ -88,8 +89,8 @@ type OnyxDataWithErrorFields = {
errorFields?: ErrorFields;
};

function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData, fieldName: string): Errors {
const errorsForField = onyxData.errorFields?.[fieldName] ?? {};
function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: OnyxEntry<TOnyxData>, fieldName: string): Errors {
const errorsForField = onyxData?.errorFields?.[fieldName] ?? {};

if (Object.keys(errorsForField).length === 0) {
return {};
Expand All @@ -99,8 +100,8 @@ function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData
return {[key]: getErrorMessageWithTranslationData(errorsForField[key])};
}

function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData, fieldName: string): Errors {
const errorsForField = onyxData.errorFields?.[fieldName] ?? {};
function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: OnyxEntry<TOnyxData>, fieldName: string): Errors {
const errorsForField = onyxData?.errorFields?.[fieldName] ?? {};

if (Object.keys(errorsForField).length === 0) {
return {};
Expand All @@ -113,8 +114,8 @@ function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxDa
/**
* Method used to get the latest error field for any field
*/
function getLatestErrorFieldForAnyField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData): Errors {
const errorFields = onyxData.errorFields ?? {};
function getLatestErrorFieldForAnyField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: OnyxEntry<TOnyxData>): Errors {
const errorFields = onyxData?.errorFields ?? {};

if (Object.keys(errorFields).length === 0) {
return {};
Expand Down Expand Up @@ -189,9 +190,9 @@ export {
getErrorMessageWithTranslationData,
getErrorsWithTranslationData,
getLatestErrorField,
getLatestErrorFieldForAnyField,
getLatestErrorMessage,
getLatestErrorMessageField,
getLatestErrorFieldForAnyField,
getMicroSecondOnyxError,
getMicroSecondOnyxErrorObject,
isReceiptError,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Onyx.connect({
*/
function getActivePolicies(policies: OnyxCollection<Policy>): Policy[] | undefined {
return Object.values(policies ?? {}).filter<Policy>(
(policy): policy is Policy => policy !== null && policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id,
(policy): policy is Policy => !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/Pusher/pusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function bindEventToChannel<EventName extends PusherEventName>(channel: Channel

let data;
try {
data = isObject(eventData) ? eventData : JSON.parse(eventData);
data = isObject(eventData) ? eventData : JSON.parse(eventData as string);
} catch (err) {
Log.alert('[Pusher] Unable to parse single JSON event data from Pusher', {error: err, eventData});
return;
Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ function getLastVisibleMessage(reportID: string, actionsToMerge: OnyxCollection<
/**
* A helper method to filter out report actions keyed by sequenceNumbers.
*/
function filterOutDeprecatedReportActions(reportActions: ReportActions | null): ReportAction[] {
function filterOutDeprecatedReportActions(reportActions: OnyxEntry<ReportActions>): ReportAction[] {
return Object.entries(reportActions ?? {})
.filter(([key, reportAction]) => !isReportActionDeprecated(reportAction, key))
.map((entry) => entry[1]);
Expand All @@ -644,7 +644,7 @@ function filterOutDeprecatedReportActions(reportActions: ReportActions | null):
* to ensure they will always be displayed in the same order (in case multiple actions have the same timestamp).
* This is all handled with getSortedReportActions() which is used by several other methods to keep the code DRY.
*/
function getSortedReportActionsForDisplay(reportActions: ReportActions | null | ReportAction[], shouldIncludeInvisibleActions = false): ReportAction[] {
function getSortedReportActionsForDisplay(reportActions: OnyxEntry<ReportActions> | ReportAction[], shouldIncludeInvisibleActions = false): ReportAction[] {
let filteredReportActions: ReportAction[] = [];
if (!reportActions) {
return [];
Expand All @@ -668,7 +668,7 @@ function getSortedReportActionsForDisplay(reportActions: ReportActions | null |
* Additionally, archived #admins and #announce do not have the closed report action so we will return null if none is found.
*
*/
function getLastClosedReportAction(reportActions: ReportActions | null): OnyxEntry<ReportAction> {
function getLastClosedReportAction(reportActions: OnyxEntry<ReportActions>): OnyxEntry<ReportAction> {
// If closed report action is not present, return early
if (!Object.values(reportActions ?? {}).some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED)) {
return null;
Expand Down Expand Up @@ -721,7 +721,7 @@ function getLinkedTransactionID(reportActionOrID: string | OnyxEntry<ReportActio
return reportAction.originalMessage?.IOUTransactionID ?? null;
}

function getReportAction(reportID: string, reportActionID: string): OnyxEntry<ReportAction> {
function getReportAction(reportID: string, reportActionID: string): ReportAction | null {
return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]?.[reportActionID] ?? null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ Onyx.connect({
},
});

let allPersonalDetails: OnyxCollection<PersonalDetails>;
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({
Expand Down
3 changes: 1 addition & 2 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import type {OnfidoDataWithApplicantID} from '@components/Onfido/types';
Expand Down Expand Up @@ -71,7 +70,7 @@ function openPlaidView() {
clearPlaid().then(() => ReimbursementAccount.setBankAccountSubStep(CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID));
}

function setPlaidEvent(eventName: OnyxEntry<string>) {
function setPlaidEvent(eventName: string | null) {
Onyx.set(ONYXKEYS.PLAID_CURRENT_EVENT, eventName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/FormActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function clearErrorFields(formID: OnyxFormKey) {
}

function setDraftValues(formID: OnyxFormKey, draftValues: NullishDeep<OnyxValue<OnyxFormDraftKey>>) {
Onyx.merge(`${formID}Draft`, draftValues);
Onyx.merge(`${formID}Draft`, draftValues ?? null);
}

function clearDraftValues(formID: OnyxFormKey) {
Expand Down
12 changes: 6 additions & 6 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,15 +1233,15 @@ function getDeleteTrackExpenseInformation(
failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: transaction,
value: transaction ?? null,
});
}

if (Permissions.canUseViolations(betas)) {
failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
value: transactionViolations,
value: transactionViolations ?? null,
});
}

Expand Down Expand Up @@ -1320,7 +1320,7 @@ function getMoneyRequestInformation(
}

if (!chatReport) {
chatReport = ReportUtils.getChatByParticipants([payerAccountID]);
chatReport = ReportUtils.getChatByParticipants([payerAccountID]) ?? null;
}

// If we still don't have a report, it likely doens't exist and we need to build an optimistic one
Expand Down Expand Up @@ -4657,15 +4657,15 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: transaction,
value: transaction ?? null,
},
];

if (Permissions.canUseViolations(betas)) {
failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
value: transactionViolations,
value: transactionViolations ?? null,
});
}

Expand Down Expand Up @@ -5716,7 +5716,7 @@ function detachReceipt(transactionID: string) {
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: transaction,
value: transaction ?? null,
},
];

Expand Down
Loading
Loading