Skip to content

Commit 154bbd4

Browse files
authored
Type Declarations (#11)
* Type declarations * Real version update * Line space and indentation
1 parent 12f7dc4 commit 154bbd4

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dollarshaveclub/react-passage",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Link and Redirect to routes safely in your react applications",
55
"author": "Jacob Kelley <[email protected]>",
66
"license": "MIT",
@@ -9,6 +9,7 @@
99
"module": "dist/index.es.js",
1010
"jsnext:main": "dist/index.es.js",
1111
"unpkg": "dist/index.js",
12+
"types": "types/index.d.ts",
1213
"engines": {
1314
"node": ">=8",
1415
"npm": ">=5"
@@ -63,6 +64,8 @@
6364
"@babel/plugin-transform-runtime": "^7.1.0",
6465
"@babel/preset-env": "^7.1.0",
6566
"@babel/preset-react": "^7.0.0",
67+
"@types/react": "^16.7.13",
68+
"@types/react-router-dom": "^4.3.1",
6669
"babel-core": "^7.0.0-bridge.0",
6770
"babel-eslint": "^10.0.1",
6871
"babel-jest": "^23.4.2",

src/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ const getRoutes = (children, targets, matches = []) => {
1212
matches.push(child)
1313
if (child.props.children) return getRoutes(child.props.children, targets, matches)
1414
})
15-
return matches.filter((child) => targets.includes(child.type))
15+
return matches.filter(child => {
16+
for (const index in targets) {
17+
if (targets[index].toString() === child.type.toString()) {
18+
return true
19+
}
20+
}
21+
return false
22+
})
1623
}
1724

1825
// Takes in children and returns a function that will be passed via context.

types/index.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { LocationDescriptor } from 'history'
2+
import * as React from 'react'
3+
import { LinkProps, RedirectProps as ReactRouterRedirectProps, Route } from 'react-router-dom'
4+
5+
export const Link: React.FunctionComponent<LinkProps>
6+
7+
interface RedirectProps extends ReactRouterRedirectProps, Readonly<{
8+
via?: (to: LocationDescriptor) => void
9+
}> {}
10+
11+
export const Redirect: React.FunctionComponent<RedirectProps>
12+
13+
interface PassageProps extends Readonly<{
14+
children: React.ReactNode
15+
targets?: Array<typeof Route>
16+
}> {}
17+
18+
export const Passage: React.FunctionComponent<PassageProps>

0 commit comments

Comments
 (0)