Skip to content

Commit

Permalink
feat(entity): add undefined to Dictionary's index signature
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-okrushko committed Apr 9, 2019
1 parent 00b550e commit 8c1badb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/entity/spec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ts_test_library(
),
deps = [
"//modules/entity",
"//modules/store",
"@npm//rxjs",
],
)
Expand All @@ -17,6 +18,5 @@ jasmine_node_test(
name = "test",
deps = [
":test_lib",
"//modules/entity",
],
)
9 changes: 9 additions & 0 deletions modules/entity/spec/state_selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AnimalFarm,
TheGreatGatsby,
} from './fixtures/book';
import { MemoizedSelector, createSelector } from '@ngrx/store';

describe('Entity State Selectors', () => {
describe('Composed Selectors', () => {
Expand Down Expand Up @@ -89,6 +90,14 @@ describe('Entity State Selectors', () => {
expect(entities).toEqual(state.entities);
});

it('should type single entity from Dictonary as entity type or undefined', () => {
// MemoizedSelector acts like a type checker
const singleEnitity: MemoizedSelector<
EntityState<BookModel>,
BookModel | undefined
> = createSelector(selectors.selectEntities, enitites => enitites[0]);
});

it('should create a selector for selecting the list of models', () => {
const models = selectors.selectAll(state);

Expand Down
4 changes: 2 additions & 2 deletions modules/entity/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export type IdSelectorNum<T> = (model: T) => number;
export type IdSelector<T> = IdSelectorStr<T> | IdSelectorNum<T>;

export interface DictionaryNum<T> {
[id: number]: T;
[id: number]: T | undefined;
}

export abstract class Dictionary<T> implements DictionaryNum<T> {
[id: string]: T;
[id: string]: T | undefined;
}

export interface UpdateStr<T> {
Expand Down

0 comments on commit 8c1badb

Please sign in to comment.