-
Notifications
You must be signed in to change notification settings - Fork 672
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
Type error when using created selectors as input for a new selector. #237
Comments
I noticed it as well, would be nice to add your example to https://github.com/reactjs/reselect/blob/master/typescript_test/test.ts so that we handle this use case in the typescript test and fix it. I think that is because |
I tried to reproduce your issue but didn't get any error : alex3165@388da06#diff-2fe2e76dc80d303b543f572094baf958R35 |
The strange thing is the code compiles fine and runs without errors, just the editor is showing the error and therefore autocompletion is broken. I tried sublime and atom both showing this error when hovering over |
@kevinwardenga It is probably because your IDE is using an old version of Typescript |
I've already checked that, it's using the latest typescript version (2.2.2). Also the following type declarations are showing an error: export type 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 OutputParametricSelector<S, P, R, C> extends ParametricSelector<S, P, R> {
resultFunc: C;
recomputations: () => number;
resetRecomputations: () => number;
} which says:
for Update: 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 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;
resetRecomputations: () => number;
} |
As far as I remember, extending type alias was an error before. Although, latest TypeScript doesn't give me any error. Maybe your editor uses some built-in TypeScript compiler that is outdated. Either way, I've created a PR #240 that replaces type aliases with interfaces. I also added a test for nested selectors. |
@aikoven you're right it's possible since version 2.2, i know managed to get sublime to recognize the local typescript version, had do reinstall the typescript package and now it's properly using version 2.2 and all errors are gone. But it should be good to note in the docs that you need typescript version 2.2.x to use this package or use interfaces instead of types like in your pull request. |
@kevinwardenga I don't see any reason to constraint version of TS since there are no other features that require latest. |
@aikoven yep when your pull request is getting merged there's no need to contraint the TS version. |
After the upgrade to version 3.0.0 the typescript compiler complains about a non matching argument type. Using the following code:
Is producing the following error:
The same code doesn't show any typing error with version 2.5.4.
The text was updated successfully, but these errors were encountered: