mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[hookrouter] Add type definitions for react hookrouter. (#35443)
* Add tests. * Add types. * Add package.json with csstype dependency. * Add tslint.json and tsconfig.json.
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
c46c58352f
commit
268fe2d0fb
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
A,
|
||||
setLinkProps,
|
||||
useControlledInterceptor,
|
||||
interceptRoute,
|
||||
get,
|
||||
remove,
|
||||
navigate,
|
||||
setPath,
|
||||
getPath,
|
||||
getTitle,
|
||||
useRedirect,
|
||||
useRoutes,
|
||||
usePath,
|
||||
getWorkingPath,
|
||||
getBasepath,
|
||||
resolvePath,
|
||||
prepareRoute,
|
||||
useQueryParams
|
||||
} from 'hookrouter';
|
||||
import * as React from 'react';
|
||||
|
||||
// $ExpectType AProps
|
||||
setLinkProps({ href: '/route' });
|
||||
|
||||
// $ExpectError
|
||||
setLinkProps({ onClick: () => null });
|
||||
|
||||
// $ExpectType ReactHTMLElement<HTMLAnchorElement>
|
||||
A({ href: '/route' });
|
||||
|
||||
// $ExpectType [InterceptedPath, () => void, () => void, () => void]
|
||||
useControlledInterceptor();
|
||||
|
||||
// $ExpectType string[]
|
||||
interceptRoute('/route1', '/route2');
|
||||
|
||||
// $ExpectType RouteObject | null
|
||||
get(2);
|
||||
|
||||
// $ExpectType void
|
||||
remove(2);
|
||||
|
||||
// $ExpectType [QueryParams, (inObj: QueryParams, replace?: boolean | undefined) => void]
|
||||
useQueryParams();
|
||||
|
||||
// $ExpectType void
|
||||
useRedirect('/route1', '/route2');
|
||||
|
||||
// $ExpectError
|
||||
navigate();
|
||||
|
||||
// $ExpectError
|
||||
navigate(1);
|
||||
|
||||
// $ExpectType string
|
||||
getBasepath();
|
||||
|
||||
// $ExpectType string
|
||||
resolvePath('path');
|
||||
|
||||
// $ExpectType [RegExp, string[]]
|
||||
prepareRoute('/route');
|
||||
|
||||
// $ExpectType void
|
||||
setPath('/route');
|
||||
|
||||
// $ExpectType string
|
||||
usePath();
|
||||
|
||||
// $ExpectType string
|
||||
usePath(true, true);
|
||||
|
||||
// $ExpectType string
|
||||
getWorkingPath('id');
|
||||
|
||||
// $ExpectType ReactNode
|
||||
useRoutes({ '/route:id': ({ id }) => React.createElement('div', { children: 'Route Component' }) });
|
||||
|
||||
// $ExpectType string
|
||||
getTitle();
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
// Type definitions for hookrouter 2.2
|
||||
// Project: https://github.com/Paratron/hookrouter
|
||||
// Definitions by: Mete Can Eris <https://github.com/mcaneris>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.4
|
||||
import * as React from 'react';
|
||||
export namespace HookRouter {
|
||||
type InterceptedPath = string | null;
|
||||
interface AProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> { href: string; }
|
||||
interface QueryParams { [key: string]: any; }
|
||||
interface RouteObject { [key: string]: (params: QueryParams) => any; }
|
||||
}
|
||||
export function setLinkProps(props: HookRouter.AProps): HookRouter.AProps;
|
||||
export function A(props: HookRouter.AProps): React.ReactHTMLElement<HTMLAnchorElement>;
|
||||
export function confirmNavigation(): void;
|
||||
export function resetPath(): void;
|
||||
export function stopInterception(): void;
|
||||
export function useControlledInterceptor(): [
|
||||
HookRouter.InterceptedPath,
|
||||
typeof confirmNavigation,
|
||||
typeof resetPath,
|
||||
typeof stopInterception
|
||||
];
|
||||
export function interceptRoute(previousRoute: string, nextRoute: string): string[];
|
||||
export function get(componentId: number): HookRouter.RouteObject | null;
|
||||
export function remove(componentId: number): void;
|
||||
export function useInterceptor(handlerFn: (...args: any[]) => any): () => typeof remove;
|
||||
export function setQueryParams(inObj: HookRouter.QueryParams, replace?: boolean): void;
|
||||
export function getQueryParams(): HookRouter.QueryParams;
|
||||
export function queryStringToObject(inStr: string): HookRouter.QueryParams;
|
||||
export function objectToQueryString(inObj: HookRouter.QueryParams): string;
|
||||
export function useQueryParams(): [HookRouter.QueryParams, typeof setQueryParams];
|
||||
export function useRedirect(
|
||||
fromURL: string,
|
||||
toURL: string,
|
||||
queryParams?: HookRouter.QueryParams | null,
|
||||
replace?: boolean
|
||||
): void;
|
||||
export function setBasepath(inBasepath: string): void;
|
||||
export function getBasepath(): string;
|
||||
export function resolvePath(inPath: string): string;
|
||||
export function prepareRoute(inRoute: string): [RegExp, string[]];
|
||||
export function navigate(
|
||||
url: string,
|
||||
replace: true,
|
||||
queryParams?: HookRouter.QueryParams | null,
|
||||
replaceQueryParams?: boolean
|
||||
): void;
|
||||
export function setPath(inPath: string): void;
|
||||
export function getPath(): string;
|
||||
export function usePath(active?: boolean, withBasePath?: boolean): string;
|
||||
export function updatePathHooks(): void;
|
||||
export function getWorkingPath(parentRouterId: string): string;
|
||||
export function useRoutes(routeObj: HookRouter.RouteObject): React.ReactNode;
|
||||
export function useTitle(inString: string): void;
|
||||
export function getTitle(): string;
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"csstype": "^2.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"hookrouter-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user