Skip to content

Commit

Permalink
refactor: fix type errors with @ngrx/data
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Oct 25, 2021
1 parent 242a803 commit 8c510b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
4 changes: 3 additions & 1 deletion modules/data/src/effects/entity-cache-effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export class EntityCacheEffects {
// Emit which ever gets there first; the other observable is terminated.
return race(c, d);
} catch (err) {
return this.handleSaveEntitiesError$(action)(err);
return this.handleSaveEntitiesError$(action)(
err as DataServiceError | Error
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/data/src/effects/entity-effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class EntityEffects {

// Emit which ever gets there first; the other observable is terminated.
return race(c, d);
} catch (err) {
return this.handleError$(action)(err);
} catch (err: unknown) {
return this.handleError$(action)(err as Error);
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ export class EntityEffects {
// ensure observable takes some time,
// as app likely assumes asynchronous response.
return (error: Error) =>
of(this.resultHandler.handleError(action)(error)).pipe(
of(this.resultHandler.handleError(action)(error as Error)).pipe(
delay(this.responseDelay, this.scheduler || asyncScheduler)
);
}
Expand Down
31 changes: 10 additions & 21 deletions modules/data/src/reducers/entity-cache-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,8 @@ export class EntityCacheReducerFactory {
entityCache: EntityCache,
action: SaveEntities
) {
const {
changeSet,
correlationId,
isOptimistic,
mergeStrategy,
tag,
} = action.payload;
const { changeSet, correlationId, isOptimistic, mergeStrategy, tag } =
action.payload;

try {
changeSet.changes.forEach((item) => {
Expand All @@ -243,8 +238,8 @@ export class EntityCacheReducerFactory {
throw act.payload.error;
}
});
} catch (error) {
action.payload.error = error;
} catch (error: unknown) {
action.payload.error = error as Error;
}

return entityCache;
Expand Down Expand Up @@ -293,13 +288,8 @@ export class EntityCacheReducerFactory {
entityCache: EntityCache,
action: SaveEntitiesSuccess
) {
const {
changeSet,
correlationId,
isOptimistic,
mergeStrategy,
tag,
} = action.payload;
const { changeSet, correlationId, isOptimistic, mergeStrategy, tag } =
action.payload;

changeSet.changes.forEach((item) => {
const entityName = item.entityName;
Expand Down Expand Up @@ -344,18 +334,17 @@ export class EntityCacheReducerFactory {
) {
const entityName = action.payload.entityName;
const collection = cache[entityName];
const reducer = this.entityCollectionReducerRegistry.getOrCreateReducer(
entityName
);
const reducer =
this.entityCollectionReducerRegistry.getOrCreateReducer(entityName);

let newCollection: EntityCollection;
try {
newCollection = collection
? reducer(collection, action)
: reducer(this.entityCollectionCreator.create(entityName), action);
} catch (error) {
} catch (error: unknown) {
this.logger.error(error);
action.payload.error = error;
action.payload.error = error as Error;
}

return action.payload.error || collection === newCollection!
Expand Down

0 comments on commit 8c510b7

Please sign in to comment.