Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions libs/ngrx-toolkit/src/lib/with-data-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ describe('withDataService', () => {
});
}));

it('should ensure that collection name is provided in callState ', () => {
// @ts-expect-error should not allow `withCallState` without collection name if `withDataService` has it
signalStore(
withCallState(),
withEntities({
entity: type<Flight>(),
collection: 'flight',
}),
withDataService({
dataServiceType: MockFlightService,
filter: { from: 'Paris', to: 'New York' },
collection: 'flight',
})
);
});

// TODO 3A: setting error state (without named collection)
// TODO 3B: setting error state (with named collection)
});
Expand Down
11 changes: 6 additions & 5 deletions libs/ngrx-toolkit/src/lib/with-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import {
} from '@ngrx/signals';
import {
CallState,
NamedCallStateSlice,
getCallStateKeys,
setError,
setLoaded,
setLoading,
} from './with-call-state';
import {
NamedEntityState,
setAllEntities,
EntityId,
addEntity,
updateEntity,
removeEntity,
} from '@ngrx/signals/entities';
import { EntityState, NamedEntityComputed } from './shared/signal-store-models';
import { EntityState } from './shared/signal-store-models';

export type Filter = Record<string, unknown>;
export type Entity = { id: EntityId };
Expand Down Expand Up @@ -201,10 +203,9 @@ export function withDataService<
filter: F;
collection: Collection;
}): SignalStoreFeature<
// These alternatives break type inference:
// state: { callState: CallState } & NamedEntityState<E, Collection>,
// state: NamedEntityState<E, Collection>,
EmptyFeatureResult & { props: NamedEntityComputed<E, Collection> },
EmptyFeatureResult & {
state: NamedCallStateSlice<Collection> & NamedEntityState<E, Collection>;
},
{
state: NamedDataServiceState<E, F, Collection>;
props: NamedDataServiceComputed<E, Collection>;
Expand Down