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

Add types for redux-router5 #210

Merged
merged 2 commits into from
Nov 1, 2017
Merged

Add types for redux-router5 #210

merged 2 commits into from
Nov 1, 2017

Conversation

jkelin
Copy link
Contributor

@jkelin jkelin commented Oct 22, 2017

No description provided.

@faergeek
Copy link
Contributor

@jkelin I'm just trying to use these definitions, but already seeing a few errors. I can fix them, how'd be better to do it? Fork your fork and send a PR may be?

@jkelin
Copy link
Contributor Author

jkelin commented Oct 23, 2017

Any help is greatly appreciated, I have added you as collaborator for https://github.com/jkelin/router5 so you can work directly on branches for these PRs.

What errors are you seeing? Compilation errors? Type errors (as in types not representing the actual data)?

const CAN_DEACTIVATE = '@@router5/CAN_DEACTIVATE';
const CAN_ACTIVATE = '@@router5/CAN_ACTIVATE';

export const actionTypes: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the correct pattern seems to be NAVIGATE_TO: typeof NAVIGATE_TO or else actionTypes keys seen as any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah correct, thank you!


export function reduxPlugin<TState extends RouterState>(dispatch: Dispatch<TState>): Plugin;

export function routeNodeSelector<TState extends RouterState>(routeNode: string, reducerKey?: string): (state: TState) => Route;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here at the end should be (state: {router: TState}) => RouterState instead of (state: TState) => Route;. Because by default (or maybe even always) router5Reducer is meant to be used as such:

combineReducers({
  // ...
  router: router5Reducer,
  // ...
})

And we should get RouterState instead of Route from it, because Route is for routes description, not for any state. And it's not needed to import it with that change :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with export function routeNodeSelector<TState extends { router: RouterState }>(routeNode: string, reducerKey?: string): (state: TState) => Route; because I want to allow different root state not different RouterState.

@faergeek
Copy link
Contributor

@jkelin I wrote comments on relevant lines. If nothing breaks for you and you can apply them, please do. I'm a bit busy right now :-)

@jkelin
Copy link
Contributor Author

jkelin commented Oct 23, 2017

Fixed, thank you. If you see anything else, please let me know.

@faergeek
Copy link
Contributor

@jkelin Cool, thanks 👍 I will definitely let you know of other issues if there's any. I'm in the process of migrating a big project to TypeScript right now :-)

@troch
Copy link
Member

troch commented Nov 1, 2017

@jkelin @faergeek is this one ready to go?

@troch
Copy link
Member

troch commented Nov 1, 2017

Giving you collaborator access so you can contribute directly on the repo and merge when done.

@faergeek
Copy link
Contributor

faergeek commented Nov 1, 2017

@troch I'm not sure yet, didn't migrate everything. But I think merging it will not hurt anybody. We can fix types later if needed.

@troch
Copy link
Member

troch commented Nov 1, 2017

OK, I'll merge both then, cut a release later today, and you can adjust type definitions as needed

@troch troch merged commit 5f6b93f into router5:master Nov 1, 2017
@troch troch added the feature label Nov 1, 2017
@faergeek
Copy link
Contributor

faergeek commented Nov 1, 2017

@troch Can you also merge this one? Or just apply these changes manually. https://github.com/jkelin/router5/pull/1

@troch
Copy link
Member

troch commented Nov 1, 2017

No I can't it is not on this repo. Can you create a PR on this repo for it? (you shouldn't need your fork)

This was referenced Nov 1, 2017
@jkelin
Copy link
Contributor Author

jkelin commented Nov 1, 2017

Thanks both of you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants