Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Selector types for correct extension #240

Merged
merged 4 commits into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
export as namespace Reselect;

export type Selector<S, R> = (state: S) => R;
export interface Selector<S, R> {
(state: S): R;
}
export interface OutputSelector<S, R, C> extends Selector<S, R> {
resultFunc: C;
recomputations: () => number;
resetRecomputations: () => number;
}

export type ParametricSelector<S, P, R> = (state: S, props: P, ...args: any[]) => R;
export interface ParametricSelector<S, P, R> {
(state: S, props: P, ...args: any[]): R;
}
export interface OutputParametricSelector<S, P, R, C> extends ParametricSelector<S, P, R> {
resultFunc: C;
recomputations: () => number;
Expand Down
26 changes: 26 additions & 0 deletions typescript_test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ function testSelector() {
);
}

function testNestedSelector() {
type State = {foo: string, bar: number, baz: boolean};

const selector = createSelector(
createSelector(
(state: State) => state.foo,
(state: State) => state.bar,
(foo, bar) => ({foo, bar}),
),
(state: State) => state.baz,
({foo, bar}, baz) => {
const foo1: string = foo;
// typings:expect-error
const foo2: number = foo;

const bar1: number = bar;
// typings:expect-error
const bar2: string = bar;

const baz1: boolean = baz;
// typings:expect-error
const baz2: string = baz;
},
)
}

type Component<P> = (props: P) => any;

declare function connect<S, P, R>(selector: ParametricSelector<S, P, R>):
Expand Down