Skip to content

Commit

Permalink
Implement CollectionDataSet type
Browse files Browse the repository at this point in the history
  • Loading branch information
VickyStash committed Feb 27, 2024
1 parent aa4522b commit 34fc666
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,4 @@ type MissingOnyxKeysError = `Error: Types don't match, OnyxKey type is missing:
type AssertOnyxKeys = AssertTypesEqual<AllOnyxKeys, OnyxKey, MissingOnyxKeysError>;

export default ONYXKEYS;
export type {OnyxValues, OnyxKey, OnyxCollectionKey, OnyxValue, OnyxValueKey, OnyxFormKey, OnyxFormValuesMapping, OnyxFormDraftKey};
export type {OnyxValues, OnyxKey, OnyxCollectionKey, OnyxValue, OnyxValueKey, OnyxFormKey, OnyxFormValuesMapping, OnyxFormDraftKey, OnyxCollectionValuesMapping};
3 changes: 2 additions & 1 deletion src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type ONYXKEYS from '@src/ONYXKEYS';
import type CollectionDataSet from '@src/types/utils/CollectionDataSet';
import type * as OnyxCommon from './OnyxCommon';
import type PersonalDetails from './PersonalDetails';
import type {PolicyReportField} from './PolicyReportField';
Expand Down Expand Up @@ -179,7 +180,7 @@ type Report = {
reportFields?: Record<string, PolicyReportField>;
};

type ReportCollectionDataSet = Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, Report>;
type ReportCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.REPORT>;

export default Report;

Expand Down
6 changes: 6 additions & 0 deletions src/types/utils/CollectionDataSet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {OnyxCollectionKey, OnyxCollectionValuesMapping} from '@src/ONYXKEYS';

/** Helps with typing a collection item update inside Onyx.multiSet call */
type CollectionDataSet<TCollectionKey extends OnyxCollectionKey> = Record<`${TCollectionKey}${string}`, OnyxCollectionValuesMapping[TCollectionKey]>;

export default CollectionDataSet;

0 comments on commit 34fc666

Please sign in to comment.