diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts new file mode 100644 index 000000000000..0c9222a6eb32 --- /dev/null +++ b/src/types/utils/whitelistedReportKeys.ts @@ -0,0 +1,87 @@ +import type {PolicyReportField, Report} from '../onyx'; +import type * as OnyxCommon from '../onyx/OnyxCommon'; + +// List of keys that are allowed on the Report type. These should be the keys that are sent from the server. +// you need confirmation from an internal engineer that this has indeed been added to the report object that is returned as +type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< + { + avatarUrl: unknown; + avatarFileName: unknown; + chatType: unknown; + hasOutstandingChildRequest: unknown; + hasOutstandingChildTask: unknown; + isOwnPolicyExpenseChat: unknown; + isPolicyExpenseChat: unknown; + isPinned: unknown; + lastMessageText: unknown; + lastVisibleActionCreated: unknown; + lastReadTime: unknown; + lastReadSequenceNumber: unknown; + lastMentionedTime: unknown; + policyAvatar: unknown; + policyName: unknown; + oldPolicyName: unknown; + hasParentAccess: unknown; + description: unknown; + isDeletedParentAction: unknown; + policyID: unknown; + reportName: unknown; + reportID: string; + reportActionID: unknown; + chatReportID: unknown; + stateNum: unknown; + statusNum: unknown; + writeCapability: unknown; + type: unknown; + visibility: unknown; + cachedTotal: unknown; + invoiceReceiver: unknown; + lastMessageTranslationKey: unknown; + parentReportID: unknown; + parentReportActionID: unknown; + isOptimisticReport: unknown; + managerID: unknown; + lastVisibleActionLastModified: unknown; + displayName: unknown; + lastMessageHtml: unknown; + lastActorAccountID: unknown; + lastActionType: unknown; + ownerAccountID: unknown; + participants: unknown; + total: unknown; + unheldTotal: unknown; + currency: unknown; + errors: unknown; + errorFields: unknown; + isWaitingOnBankAccount: unknown; + isCancelledIOU: unknown; + iouReportID: unknown; + preexistingReportID: unknown; + nonReimbursableTotal: unknown; + isHidden: unknown; + privateNotes: unknown; + isLoadingPrivateNotes: unknown; + pendingChatMembers: unknown; + transactionThreadReportID: unknown; + fieldList: unknown; + permissions: unknown; + tripData: { + startDate: unknown; + endDate: unknown; + tripID: unknown; + }; + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: unknown; + }, + PolicyReportField['fieldID'] +>; +type ReportKeys = keyof Report; +type WhitelistedReportKeys = keyof WhitelistedReport; + +type ValidateKeys = Exclude extends never ? true : false; + +// TypeScript type-level check intended to ensure that all keys in the Report type are part of the whitelisted keys. +// However, TypeScript doesn't execute code at runtime, so this check is purely for compile-time validation. +// This validation must be always TRUE. +const testReportKeys: ValidateKeys = true; +export default testReportKeys; diff --git a/tests/unit/validateReportKeysTest.ts b/tests/unit/validateReportKeysTest.ts new file mode 100644 index 000000000000..1339b126e41b --- /dev/null +++ b/tests/unit/validateReportKeysTest.ts @@ -0,0 +1,8 @@ +import testReportKeys from '@src/types/utils/whitelistedReportKeys'; + +// This test is mainly to avoid that the testReportKeys is not removed or changed to false +describe('whitelistedReportKeys', () => { + it('testReportKeys must be true', () => { + expect(testReportKeys).toBe(true); + }); +});