Skip to content

Commit

Permalink
fix typings for cache key; bump typescript version
Browse files Browse the repository at this point in the history
  • Loading branch information
xsburg committed Feb 25, 2018
1 parent 6742aa2 commit 763f4e3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"rimraf": "^2.6.1",
"rollup": "^0.47.4",
"rollup-plugin-babel": "^3.0.1",
"typescript": "^2.4.1",
"typescript": "^2.7.2",
"typings-tester": "^0.2.2"
},
"jest": {
Expand Down
10 changes: 5 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createSelector } from 'reselect';

export type Selector<S, R> = (state: S) => R;

export type Resolver<S> = (state: S, ...args: any[]) => number | string;
export type Resolver<S> = (state: S, ...args: any[]) => any;

export type CreateSelectorInstance = typeof createSelector;

Expand All @@ -29,7 +29,7 @@ export type OutputCachedSelector<S, R, C> = (resolver: Resolver<S>, optionsOrSel

export type ParametricSelector<S, P, R> = (state: S, props: P, ...args: any[]) => R;

export type ParametricResolver<S, P> = (state: S, props: P, ...args: any[]) => number | string;
export type ParametricResolver<S, P> = (state: S, props: P, ...args: any[]) => any;

export type OutputParametricSelector<S, P, R, C> = ParametricSelector<S, P, R> & {
resultFunc: C;
Expand Down Expand Up @@ -599,9 +599,9 @@ export default function createCachedSelector<S, P, R1, R2, R3, R4, R5, R6, R7, R
res7: R7, res8: R8, res9: R9, res10: R10, res11: R11, res12: R12) => T>;

export interface ICacheObject {
set (key: string|number, selectorFn: any): void;
get (key: string|number): any;
remove (key: string|number): void;
set (key: any, selectorFn: any): void;
get (key: any): any;
remove (key: any): void;
clear (): void;
}

Expand Down
6 changes: 6 additions & 0 deletions typescript_test/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function testFlatCacheObject () {
const cacheObject = new FlatCacheObject();
cacheObject.set('foo', () => {});
cacheObject.set(1, () => {});
// typings:expect-error
cacheObject.set({}, () => {});
const result1: any = cacheObject.get('foo');
const result2: any = cacheObject.get(2);
cacheObject.remove('foo');
Expand All @@ -50,6 +52,8 @@ function testFifoCacheObject () {
const cacheObject = new FifoCacheObject({ cacheSize: 10 });
cacheObject.set('foo', () => {});
cacheObject.set(1, () => {});
// typings:expect-error
cacheObject.set({}, () => {});
const result1: any = cacheObject.get('foo');
const result2: any = cacheObject.get(2);
cacheObject.remove('foo');
Expand All @@ -75,6 +79,8 @@ function testLruCacheObject () {
const cacheObject = new LruCacheObject({ cacheSize: 10 });
cacheObject.set('foo', () => {});
cacheObject.set(1, () => {});
// typings:expect-error
cacheObject.set({}, () => {});
const result1: any = cacheObject.get('foo');
const result2: any = cacheObject.get(2);
cacheObject.remove('foo');
Expand Down
15 changes: 11 additions & 4 deletions typescript_test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,25 @@ function testArrayArgument() {
}

function testResolver() {
type State = {foo: string};
type State = {foo: string, obj: { bar: string } };

const selector = createCachedSelector(
(state: State) => state.foo,
(state: never, arg1: number) => arg1,
(state: never, arg1: number, arg2: number) => arg1 + arg2,
(foo, arg1, sum) => ({foo, arg1, sum}),
(foo, arg1, sum) => ({foo, arg1, sum})
)(
(state: never, arg1: number, arg2: number) => arg1 + arg2,
(state: never, arg1: number, arg2: number) => arg1 + arg2
);

selector({foo: 'fizz'}, 1, 2);
selector({foo: 'fizz', obj: { bar: 'bar' } }, 1, 2);

const selector2 = createCachedSelector(
(state: State) => state.obj,
obj => obj
)(
(state: never, obj) => obj
);
}

function testCustomSelectorCreator () {
Expand Down

0 comments on commit 763f4e3

Please sign in to comment.