Skip to content

Commit 6d46ac4

Browse files
authored
fix(data): type overloaded add for is optimistic true | undefined (#2906)
TypeScript only recognizes the overloads as method signatures when being overloaded not the actual implementation, added overload for the case where isOptimistic is true or undefined (default for entity). This will allow for the following: `.add(entityWithoutId, { isOptimistic: false })` `.add(entityWithId, { isOptimistic: true })` `.add(entityWithId, { // any other options without whatever settings and no explicit value for isOptimistic })` `.add(entityWithId)`
1 parent 9c54bfb commit 6d46ac4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/data/src/entity-services/entity-collection-service-base.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ export class EntityCollectionServiceBase<
143143
*/
144144
add(
145145
entity: Partial<T>,
146-
options: Omit<EntityActionOptions, 'isOptimistic'> & { isOptimistic: true }
146+
options: EntityActionOptions & { isOptimistic: false }
147+
): Observable<T>;
148+
add(
149+
entity: T,
150+
options?: EntityActionOptions & { isOptimistic?: true }
147151
): Observable<T>;
148152
add(entity: T, options?: EntityActionOptions): Observable<T> {
149153
return this.dispatcher.add(entity, options);

0 commit comments

Comments
 (0)