Skip to content

Commit b14f7eb

Browse files
committed
Improve types
1 parent 8af4d44 commit b14f7eb

6 files changed

Lines changed: 25 additions & 33 deletions

File tree

lib/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ type InitOptions = {
486486
// eslint-disable-next-line @typescript-eslint/no-explicit-any
487487
type GenericFunction = (...args: any[]) => any;
488488

489+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
490+
type GenericDeepRecord = DeepRecord<string, any>;
491+
489492
/**
490493
* Represents a record where the key is a collection member key and the value is a list of
491494
* tuples that we'll use to replace the nested objects of that collection member record with something else.
@@ -543,4 +546,5 @@ export type {
543546
WithOnyxConnectOptions,
544547
MultiMergeReplaceNullPatches,
545548
MixedOperationsQueue,
549+
GenericDeepRecord,
546550
};

lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type FastMergeOptions = {
2020
* If set to "mark", we will mark objects that are set to null instead of simply removing them,
2121
* so that we can batch changes together, without losing information about the object removal.
2222
* If set to "replace", we will completely replace the marked objects with the new value instead of merging them.
23-
* */
23+
*/
2424
objectRemovalMode?: 'mark' | 'replace' | 'none';
2525
};
2626

tests/unit/fastMergeTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type {DeepRecord} from '../../lib/types';
1+
import type {GenericDeepRecord} from '../../lib/types';
22
import utils from '../../lib/utils';
33

4-
type DeepObject = DeepRecord<string, unknown> | unknown[];
4+
type DeepObject = GenericDeepRecord | unknown[];
55

66
const testObject: DeepObject = {
77
a: 'a',

tests/unit/onyxTest.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import waitForPromisesToResolve from '../utils/waitForPromisesToResolve';
55
import OnyxUtils from '../../lib/OnyxUtils';
66
import type OnyxCache from '../../lib/OnyxCache';
77
import StorageMock from '../../lib/storage';
8-
import type {DeepRecord, OnyxCollection, OnyxUpdate} from '../../lib/types';
8+
import type {GenericDeepRecord, OnyxCollection, OnyxUpdate} from '../../lib/types';
99
import type GenericCollection from '../utils/GenericCollection';
1010
import type {Connection} from '../../lib/OnyxConnectionManager';
1111

@@ -858,7 +858,6 @@ describe('Onyx', () => {
858858
// When we pass it to Onyx.update
859859
// @ts-expect-error This is an invalid call to Onyx.update
860860
Onyx.update(data);
861-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
862861
} catch (error) {
863862
if (error instanceof Error) {
864863
// Then we should expect the error message below
@@ -875,7 +874,6 @@ describe('Onyx', () => {
875874
// When we pass it to Onyx.update
876875
// @ts-expect-error This is an invalid call to Onyx.update
877876
Onyx.update(data);
878-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
879877
} catch (error) {
880878
if (error instanceof Error) {
881879
// Then we should expect the error message below
@@ -1757,8 +1755,7 @@ describe('Onyx', () => {
17571755
});
17581756

17591757
it('replacing old object after null merge', async () => {
1760-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1761-
const entry1: DeepRecord<string, any> = {
1758+
const entry1: GenericDeepRecord = {
17621759
sub_entry1: {
17631760
id: 'sub_entry1',
17641761
someKey: 'someValue',
@@ -1799,8 +1796,7 @@ describe('Onyx', () => {
17991796
});
18001797

18011798
it('setting new object after null merge', async () => {
1802-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1803-
const entry1: DeepRecord<string, any> = {
1799+
const entry1: GenericDeepRecord = {
18041800
sub_entry1: {
18051801
id: 'sub_entry1',
18061802
someKey: 'someValue',
@@ -1872,8 +1868,7 @@ describe('Onyx', () => {
18721868
});
18731869

18741870
it('setting new object after null merge of a primitive property', async () => {
1875-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1876-
const entry1: DeepRecord<string, any> = {
1871+
const entry1: GenericDeepRecord = {
18771872
sub_entry1: {
18781873
id: 'sub_entry1',
18791874
someKey: 'someValue',
@@ -1933,8 +1928,7 @@ describe('Onyx', () => {
19331928
});
19341929

19351930
it('replacing nested object during updates', async () => {
1936-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1937-
const entry1: DeepRecord<string, any> | undefined = {
1931+
const entry1: GenericDeepRecord | undefined = {
19381932
id: 'entry1',
19391933
someKey: 'someValue',
19401934
};
@@ -1945,8 +1939,7 @@ describe('Onyx', () => {
19451939
},
19461940
});
19471941

1948-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1949-
let entry1ExpectedResult = lodashCloneDeep(entry1) as DeepRecord<string, any> | undefined;
1942+
let entry1ExpectedResult = lodashCloneDeep(entry1) as GenericDeepRecord | undefined;
19501943
const queuedUpdates: OnyxUpdate[] = [];
19511944

19521945
queuedUpdates.push({
@@ -2002,15 +1995,14 @@ describe('Onyx', () => {
20021995

20031996
describe('mergeCollection', () => {
20041997
it('replacing old object after null merge', async () => {
2005-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2006-
const entry1: DeepRecord<string, any> = {
1998+
const entry1: GenericDeepRecord = {
20071999
sub_entry1: {
20082000
id: 'sub_entry1',
20092001
someKey: 'someValue',
20102002
},
20112003
};
2012-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2013-
const entry2: DeepRecord<string, any> = {
2004+
2005+
const entry2: GenericDeepRecord = {
20142006
sub_entry2: {
20152007
id: 'sub_entry2',
20162008
someKey: 'someValue',
@@ -2132,8 +2124,7 @@ describe('Onyx', () => {
21322124
});
21332125

21342126
it('replacing old object after null merge', async () => {
2135-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2136-
const entry1: DeepRecord<string, any> = {
2127+
const entry1: GenericDeepRecord = {
21372128
sub_entry1: {
21382129
id: 'sub_entry1',
21392130
someKey: 'someValue',
@@ -2165,8 +2156,7 @@ describe('Onyx', () => {
21652156
});
21662157

21672158
it('setting new object after null merge', async () => {
2168-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2169-
const entry1: DeepRecord<string, any> = {
2159+
const entry1: GenericDeepRecord = {
21702160
sub_entry1: {
21712161
id: 'sub_entry1',
21722162
someKey: 'someValue',
@@ -2225,8 +2215,7 @@ describe('Onyx', () => {
22252215
});
22262216

22272217
it('setting new object after null merge of a primitive property', async () => {
2228-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2229-
const entry1: DeepRecord<string, any> = {
2218+
const entry1: GenericDeepRecord = {
22302219
sub_entry1: {
22312220
id: 'sub_entry1',
22322221
someKey: 'someValue',

tests/unit/onyxUtilsTest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Onyx from '../../lib';
22
import OnyxUtils from '../../lib/OnyxUtils';
3-
import type {DeepRecord} from '../../lib/types';
3+
import type {GenericDeepRecord} from '../../lib/types';
44
import utils from '../../lib/utils';
55

6-
const testObject: DeepRecord<string, unknown> = {
6+
const testObject: GenericDeepRecord = {
77
a: 'a',
88
b: {
99
c: 'c',
@@ -15,7 +15,7 @@ const testObject: DeepRecord<string, unknown> = {
1515
},
1616
};
1717

18-
const testMergeChanges: Array<DeepRecord<string, unknown>> = [
18+
const testMergeChanges: GenericDeepRecord[] = [
1919
{
2020
b: {
2121
d: {
@@ -165,7 +165,7 @@ describe('OnyxUtils', () => {
165165
});
166166

167167
it('should merge data correctly when applying batched changes', () => {
168-
const batchedChanges: DeepRecord<string, unknown> = {
168+
const batchedChanges: GenericDeepRecord = {
169169
b: {
170170
d: {
171171
i: 'i',

tests/utils/collections/reportActions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {randAggregation, randBoolean, randWord} from '@ngneat/falso';
22
import {format} from 'date-fns';
33
import {createCollection} from './createCollection';
4-
import type {DeepRecord} from '../../../lib/types';
4+
import type {GenericDeepRecord} from '../../../lib/types';
55

66
const getRandomDate = (): string => {
77
const randomTimestamp = Math.random() * new Date().getTime();
@@ -19,8 +19,7 @@ const getRandomReportActions = (collection: string, length = 10000) =>
1919
length,
2020
);
2121

22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
export default function createRandomReportAction(index: number): DeepRecord<string, any> {
22+
export default function createRandomReportAction(index: number): GenericDeepRecord {
2423
return {
2524
actionName: randWord(),
2625
reportActionID: index.toString(),

0 commit comments

Comments
 (0)