Skip to content

Commit

Permalink
fix(data): type overloaded add for is optimistic true | undefined (#2906
Browse files Browse the repository at this point in the history
)

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)`
  • Loading branch information
yharaskrik committed Jan 31, 2021
1 parent 9c54bfb commit 6d46ac4
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ export class EntityCollectionServiceBase<
*/
add(
entity: Partial<T>,
options: Omit<EntityActionOptions, 'isOptimistic'> & { isOptimistic: true }
options: EntityActionOptions & { isOptimistic: false }
): Observable<T>;
add(
entity: T,
options?: EntityActionOptions & { isOptimistic?: true }
): Observable<T>;
add(entity: T, options?: EntityActionOptions): Observable<T> {
return this.dispatcher.add(entity, options);
Expand Down

0 comments on commit 6d46ac4

Please sign in to comment.