DefinitelyTyped/types/hookrouter/hookrouter-tests.ts
Can Eriş 268fe2d0fb [hookrouter] Add type definitions for react hookrouter. (#35443)
* Add tests.

* Add types.

* Add package.json with csstype dependency.

* Add tslint.json and tsconfig.json.
2019-05-14 14:51:43 -07:00

82 lines
1.4 KiB
TypeScript

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();