diff --git a/types/react-router-guard/index.d.ts b/types/react-router-guard/index.d.ts new file mode 100644 index 0000000000..3ec6438d18 --- /dev/null +++ b/types/react-router-guard/index.d.ts @@ -0,0 +1,47 @@ +// Type definitions for react-router-guard 2.3 +// Project: https://github.com/laptransang/react-router-guard#readme +// Definitions by: TSL +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as React from 'react'; +import * as H from 'history'; + +export const history: H.History; + +export { + Loadable +} from 'react-loadable'; + +export { + BrowserRouter, + Link, + NavLink, + Route, + Router, + Switch, +} from 'react-router-dom'; + +export { + Redirect, +} from 'react-router'; + +export function lazy>( + factory: () => Promise<{ default: T }> +): React.LazyExoticComponent; + +export interface RouterGuardConfigProps { + path: string; + component: React.LazyExoticComponent; + canActivate?: Array<() => Promise>; + redirect?: string; + exact?: boolean; + routes?: RouterGuardConfigProps[]; +} + +export interface RouterGuardProps { + config: RouterGuardConfigProps[]; + history?: H.History; + loading?: boolean | React.ReactElement; +} + +export class RouterGuard extends React.Component {} diff --git a/types/react-router-guard/test/History.tsx b/types/react-router-guard/test/History.tsx new file mode 100644 index 0000000000..0a2914f487 --- /dev/null +++ b/types/react-router-guard/test/History.tsx @@ -0,0 +1,12 @@ +import * as React from 'react'; +import { history } from 'react-router-guard'; + +const History = () => { + React.useEffect(() => { + history.push('/test'); + }, []); + + return null; +}; + +export default History; diff --git a/types/react-router-guard/test/Layout.tsx b/types/react-router-guard/test/Layout.tsx new file mode 100644 index 0000000000..a1d597a2c4 --- /dev/null +++ b/types/react-router-guard/test/Layout.tsx @@ -0,0 +1,14 @@ +import * as React from 'react'; + +interface Props { + children: any; +} + +const Layout = ({ children }: Props) => ( + <> +

Layout Test

+ {children} + +); + +export default Layout; diff --git a/types/react-router-guard/test/Page.tsx b/types/react-router-guard/test/Page.tsx new file mode 100644 index 0000000000..3884d43da9 --- /dev/null +++ b/types/react-router-guard/test/Page.tsx @@ -0,0 +1,7 @@ +import * as React from 'react'; + +const Page = () => ( + <>

Page Test

+); + +export default Page; diff --git a/types/react-router-guard/test/RouterGuard.tsx b/types/react-router-guard/test/RouterGuard.tsx new file mode 100644 index 0000000000..e71b2de962 --- /dev/null +++ b/types/react-router-guard/test/RouterGuard.tsx @@ -0,0 +1,28 @@ +import * as React from 'react'; +import { RouterGuard, lazy, RouterGuardConfigProps } from 'react-router-guard'; + +import checkAuth from './checkAuth'; + +const config: RouterGuardConfigProps[] = [ + { + path: '/', + component: lazy(() => import('./Layout')), + canActivate: [checkAuth], + routes: [ + { + path: '/test', + component: lazy(() => import('./Page')), + }, + ], + }, +]; + +const RouterGuardTest = () => ( + <> + + +); + +export default RouterGuardTest; diff --git a/types/react-router-guard/test/checkAuth.ts b/types/react-router-guard/test/checkAuth.ts new file mode 100644 index 0000000000..abc8ffe874 --- /dev/null +++ b/types/react-router-guard/test/checkAuth.ts @@ -0,0 +1,5 @@ +export default function checkAuth(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); +} diff --git a/types/react-router-guard/tsconfig.json b/types/react-router-guard/tsconfig.json new file mode 100644 index 0000000000..742078d083 --- /dev/null +++ b/types/react-router-guard/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "jsx": "react", + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "test/RouterGuard.tsx", + "test/Page.tsx", + "test/Layout.tsx", + "test/History.tsx" + ] +} diff --git a/types/react-router-guard/tslint.json b/types/react-router-guard/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-router-guard/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }