{"action":"created","issue":{"url":"https://api.github.com/repos/reach/router/issues/24","repository_url":"https://api.github.com/repos/reach/router","labels_url":"https://api.github.com/repos/reach/router/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/reach/router/issues/24/comments","events_url":"https://api.github.com/repos/reach/router/issues/24/events","html_url":"https://github.com/reach/router/pull/24","id":328650542,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkyMTM0NjIx","number":24,"title":"Add typescript types","user":{"login":"kingdaro","id":19603573,"node_id":"MDQ6VXNlcjE5NjAzNTcz","avatar_url":"https://avatars1.githubusercontent.com/u/19603573?v=4","gravatar_id":"","url":"https://api.github.com/users/kingdaro","html_url":"https://github.com/kingdaro","followers_url":"https://api.github.com/users/kingdaro/followers","following_url":"https://api.github.com/users/kingdaro/following{/other_user}","gists_url":"https://api.github.com/users/kingdaro/gists{/gist_id}","starred_url":"https://api.github.com/users/kingdaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kingdaro/subscriptions","organizations_url":"https://api.github.com/users/kingdaro/orgs","repos_url":"https://api.github.com/users/kingdaro/repos","events_url":"https://api.github.com/users/kingdaro/events{/privacy}","received_events_url":"https://api.github.com/users/kingdaro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-06-01T20:27:49Z","updated_at":"2018-06-03T21:50:20Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/reach/router/pulls/24","html_url":"https://github.com/reach/router/pull/24","diff_url":"https://github.com/reach/router/pull/24.diff","patch_url":"https://github.com/reach/router/pull/24.patch"},"body":"Fixes https://github.com/reach/router/issues/11\r\n\r\nAs I mentioned in another issue, one thing I'm not sure about is how to handle the `path` property on route components. Here's a usage example of what I came up with:\r\n\r\n```jsx\r\nimport { RouteComponentMatchingProps, Router } from \"@reach/router\"\r\nimport React from \"react\"\r\nimport { render } from \"react-dom\"\r\n\r\nlet Home = () => <div>Home</div>\r\nlet Dash = () => <div>Dash</div>\r\n\r\nconst HomeRoute = Home as React.SFC<RouteComponentMatchingProps>\r\nconst DashRoute = Dash as React.SFC<RouteComponentMatchingProps>\r\n\r\nrender(\r\n  <Router>\r\n    <HomeRoute path=\"/\" />\r\n    <DashRoute path=\"dashboard\" />\r\n  </Router>,\r\n  document.getElementById(\"app-root\"),\r\n)\r\n```\r\n[Someone also suggested module augmentation as an alternative,](https://github.com/reach/router/issues/11#issuecomment-393999063) though that would mean allowing the `path` property to appear on _any_ component in the entire app, however it would certainly look cleaner in usage.\r\n\r\nComments on how to best handle this (and on other general corrections) are welcome."},"comment":{"url":"https://api.github.com/repos/reach/router/issues/comments/394194269","html_url":"https://github.com/reach/router/pull/24#issuecomment-394194269","issue_url":"https://api.github.com/repos/reach/router/issues/24","id":394194269,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NDE5NDI2OQ==","user":{"login":"kingdaro","id":19603573,"node_id":"MDQ6VXNlcjE5NjAzNTcz","avatar_url":"https://avatars1.githubusercontent.com/u/19603573?v=4","gravatar_id":"","url":"https://api.github.com/users/kingdaro","html_url":"https://github.com/kingdaro","followers_url":"https://api.github.com/users/kingdaro/followers","following_url":"https://api.github.com/users/kingdaro/following{/other_user}","gists_url":"https://api.github.com/users/kingdaro/gists{/gist_id}","starred_url":"https://api.github.com/users/kingdaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kingdaro/subscriptions","organizations_url":"https://api.github.com/users/kingdaro/orgs","repos_url":"https://api.github.com/users/kingdaro/repos","events_url":"https://api.github.com/users/kingdaro/events{/privacy}","received_events_url":"https://api.github.com/users/kingdaro/received_events","type":"User","site_admin":false},"created_at":"2018-06-03T21:50:20Z","updated_at":"2018-06-03T21:50:20Z","author_association":"CONTRIBUTOR","body":">  It looks like your last change breaks IntelliSense, though. The path and default props no longer appear. Not sure if this might help.\r\n\r\nI attempted to do it the way the linked answer does (with extending interfaces), but the props still don't show up on autocomplete. As far as I can tell, it's no different than what I'd done already.\r\n\r\nIf preserving autocomplete is a priority, then making `path` and `default` both optional properties on the props is another option, but then TS wouldn't error if you left both of them off. More tradeoffs ¯\\\\\\_(ツ)\\_/¯\r\n\r\nThat sounds like a fine solution to me, though. Reach Router will still error at runtime if one forgets to define a `path` or `default`.\r\n\r\n> Anyway, to clarify what I meant, I was trying to do something like this in the Router def:\r\n\r\nRight, and that unfortunately doesn't work, because JSX elements lose their typing information in usage. Elements collapse to `JSX.Element` which is `ReactElement<any>`, and is assignable to any `ReactElement<...>` type."}}
{"actor":{"display_login":"kingdaro"}}