From e1093480216dd641e15a0f2822ffac164f44b2b2 Mon Sep 17 00:00:00 2001 From: Lenz Weber Date: Fri, 21 Feb 2020 17:04:03 +0100 Subject: [PATCH] re-add `| undefined`, remove review comments --- etc/redux-toolkit.api.md | 2 +- src/createAction.ts | 4 ---- src/entities/models.ts | 8 ++------ src/entities/sorted_state_adapter.ts | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/etc/redux-toolkit.api.md b/etc/redux-toolkit.api.md index 10cae823a8..f90952e015 100644 --- a/etc/redux-toolkit.api.md +++ b/etc/redux-toolkit.api.md @@ -159,7 +159,7 @@ export interface CreateSliceOptions implements DictionaryNum { +export interface Dictionary extends DictionaryNum { // (undocumented) [id: string]: T | undefined; } diff --git a/src/createAction.ts b/src/createAction.ts index 0d6bdaafe2..2dea13b369 100644 --- a/src/createAction.ts +++ b/src/createAction.ts @@ -296,10 +296,6 @@ export function createAction(type: string, prepareAction?: Function): any { return actionCreator } -/** - * The previous typings implied some assertion for the types of Payload/Error/Meta, which was just not the case. - * I'd suggest we just do something like this - assert the shape of a FSA, but make no assumptions about the contents. - */ export function isFSA( action: unknown ): action is { diff --git a/src/entities/models.ts b/src/entities/models.ts index 02b4655504..9f7b217d4f 100644 --- a/src/entities/models.ts +++ b/src/entities/models.ts @@ -24,13 +24,9 @@ export interface DictionaryNum { /** * @alpha - * why was this a class, not an interface? */ -export abstract class Dictionary implements DictionaryNum { - // I get why you're adding "undefined" here, but there is not one check for it actually not being undefined down the line - // on the contrary, some casts to `any` were necessary because `Object.entities(dictionary).sort()` were not possible any more - // due to the `sort` assuming parameters of T. - [id: string]: T +export interface Dictionary extends DictionaryNum { + [id: string]: T | undefined } /** diff --git a/src/entities/sorted_state_adapter.ts b/src/entities/sorted_state_adapter.ts index b2887caccc..79e6e03f3b 100644 --- a/src/entities/sorted_state_adapter.ts +++ b/src/entities/sorted_state_adapter.ts @@ -130,7 +130,7 @@ export function createSortedStateAdapter( state.entities[selectId(model)] = model }) - const allEntities = Object.values(state.entities) + const allEntities = Object.values(state.entities) as T[] allEntities.sort(sort) const newSortedIds = allEntities.map(selectId)