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

Property 'query' does not exist on type 'Location<unknown> #472

Open
b3hr4d opened this issue Dec 25, 2020 · 5 comments
Open

Property 'query' does not exist on type 'Location<unknown> #472

b3hr4d opened this issue Dec 25, 2020 · 5 comments

Comments

@b3hr4d
Copy link

b3hr4d commented Dec 25, 2020

My dependencies :

"connected-react-router": "^6.8.0",
"react": "^16.14.0",
"react-dom": "^16.13.1",
"react-redux": "^7.2.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^3.4.4",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"source-map-explorer": "^2.5.1",
"typescript": "^3.7.5",

I want to use query like this http://localhost:3000/course?grade=item1&genre_name=item2&instrument_name=item3 and want to get query parameter from connected-react-router like this :

const mapStateToProps = (state: AppState, ownProps: Props): CourseProps => {
  return {
     query : state.router.location.query,
  };
};

It works perfect :

router: {
  location: {
    pathname: '/course',
    search: '?grade=item1&genre_name=item2&instrument_name=item3',
    hash: '',
    key: '3dwbg7',
    query: {
      grade: 'item1',
      genre_name: 'item2',
      instrument_name: 'item3'
    }
  },
  action: 'PUSH'
}

Error : Property 'query' does not exist on type 'Location<unknown>'.ts(2339)

How can I add this on Location type and fix this error ?

@nicholeuf
Copy link

Looks like a release of latest master would resolve this #410.

@Hmoulvad
Copy link

Please release master!

@b3hr4d b3hr4d closed this as completed Feb 17, 2021
@b3hr4d b3hr4d reopened this Feb 17, 2021
@robations
Copy link

I think that release was published in February.

I have 6.9.1 which says there should be a query object in the action payload (according to the TS defs), but it is coming through without. Not sure if I've missed something in the docs, but I might have to manually parse the "search" string instead:

{
    "type": "@@router/LOCATION_CHANGE",
    "payload": {
        "location": {
            "pathname": "/",
            "search": "?param=yourmom",
            "hash": ""
        },
        "action": "POP",
        "isFirstRendering": true
    }
}
  export interface LocationChangeAction<S = LocationState> {
    type: typeof LOCATION_CHANGE;
    payload: LocationChangePayload<S>;
  }

  export interface LocationChangePayload<S = LocationState> extends RouterState<S> {
    isFirstRendering: boolean;
  }

  export interface RouterState<S = LocationState> {
    location: RouterLocation<S>
    action: RouterActionType
  }

  export interface RouterLocation<S> extends Location<S> {
    query: Record<string, string> /// nope
  }

@fueher13
Copy link

The TS def for the LocationChangeAction is incorrect. From the looks of it, it only inject the query prop at the reducer level and doesn't create it in the action (which it should based on the TS def). I'm not sure if the intention was to only have the router state have query or both the action payload and router state have the query prop.

@robations
Copy link

Presumably this is an easy fix if we have a decision on what the correct resolution is. I suppose removing query from the action would be the simplest resolution. Omit<...> or similar.

@supasate are you the Lord High Decision-maker here, or can someone rock up with a PR?

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

No branches or pull requests

5 participants