Skip to content

Commit 565f21d

Browse files
fix: hide SYNC_STATUS (#205) [backport v19]
`withIndexedDB` returned a type which contained `SYNC_STATUS` as a property which required that Symbol to be publicly available. Now, we have one public type `AsyncFeatureResult`, and `AsyncStoreForFactory` which is used internally and contains `SYNC_STATUS`. Closes #200
1 parent 57fcf00 commit 565f21d

File tree

1 file changed

+15
-2
lines changed
  • libs/ngrx-toolkit/src/lib/storage-sync/internal

1 file changed

+15
-2
lines changed

libs/ngrx-toolkit/src/lib/storage-sync/internal/models.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,33 @@ export type AsyncMethods = {
2727
writeToStorage(): Promise<void>;
2828
};
2929

30+
/**
31+
* AsyncFeatureResult is used as the public interface that users interact with
32+
* when calling `withIndexedDB`. It intentionally omits the internal SYNC_STATUS
33+
* property to avoid TypeScript error TS4058 (return type of public method
34+
* includes private type).
35+
*
36+
* For internal implementation, we use AsyncStoreForFactory which includes
37+
* the SYNC_STATUS property needed for state management.
38+
*/
3039
export const SYNC_STATUS = Symbol('SYNC_STATUS');
3140
export type SyncStatus = 'idle' | 'syncing' | 'synced';
3241

42+
// Keeping it internal avoids TS4058 error
43+
export type InternalAsyncProps = AsyncFeatureResult['props'] & {
44+
[SYNC_STATUS]: WritableSignal<SyncStatus>;
45+
};
46+
3347
export type AsyncFeatureResult = EmptyFeatureResult & {
3448
methods: AsyncMethods;
3549
props: {
3650
isSynced: Signal<boolean>;
3751
whenSynced: () => Promise<void>;
38-
[SYNC_STATUS]: WritableSignal<SyncStatus>;
3952
};
4053
};
4154

4255
export type AsyncStoreForFactory<State extends object> =
43-
WritableStateSource<State> & AsyncFeatureResult['props'];
56+
WritableStateSource<State> & InternalAsyncProps;
4457

4558
export type AsyncStorageStrategy<State extends object> = ((
4659
config: Required<SyncConfig<State>>,

0 commit comments

Comments
 (0)