refactor: update type definitions for react-router-tabs (#41998)

* feat: update types for react-router-tabs

* test: rewrite tests with jsx

* refactor: change NavTab type
This commit is contained in:
Joakim Unge 2020-01-31 23:28:26 +01:00 committed by GitHub
parent 6dcaf3bed3
commit fd12683a84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 20 deletions

View File

@ -3,24 +3,17 @@
// Definitions by: Joakim Unge <https://github.com/joakimunge>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { Route, Link, RouteProps } from 'react-router-dom';
import { ReactNode } from 'react';
import { Route, Link, RouteProps, LinkProps, NavLinkProps } from 'react-router-dom';
import { ReactNode, ComponentType } from 'react';
export type AriaCurrent = 'page' | 'step' | 'location' | 'date' | 'time' | 'true';
export interface NavTabProps {
to: string | object;
replace?: boolean;
exact?: boolean;
strict?: boolean;
activeClassName?: string;
className?: string;
activeStyle?: object;
style?: object;
'aria-current'?: AriaCurrent;
export interface NavTabProps extends NavLinkProps {
style?: React.CSSProperties;
disabled?: boolean;
allowClickOnActive?: boolean;
'aria-current'?: AriaCurrent;
}
export interface RoutedTabsProps {
startPathWith?: string;
className?: string;
@ -32,5 +25,6 @@ export interface RoutedTabsProps {
children?: ReactNode;
}
export function NavTab(props: NavTabProps): Route;
export function RoutedTabs(props: RoutedTabsProps): ReactNode;
export const NavTab: ComponentType<NavTabProps>;
export const RoutedTabs: ComponentType<RoutedTabsProps>;

View File

@ -1,4 +0,0 @@
import { NavTab, RoutedTabs } from 'react-router-tabs';
NavTab({ to: 'path' }); // $ExpectType Route<RouteProps>
RoutedTabs({}); // $ExpectType ReactNode

View File

@ -0,0 +1,23 @@
import * as React from 'react';
import { NavTab, RoutedTabs } from 'react-router-tabs';
const NavTabTest: React.FC = () => {
return (
<div>
<NavTab to="/home">Home</NavTab>
</div>
);
};
const RoutedTabsTest: React.FC = () => {
return (
<RoutedTabs startPathWith="/testbed">
<NavTab to="/home">Home</NavTab>
<NavTab to="/about">About</NavTab>
<NavTab to="/contact">Contact</NavTab>
</RoutedTabs>
);
};
export { NavTabTest, RoutedTabsTest };

View File

@ -2,6 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"jsx": "react",
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
@ -12,5 +13,5 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "react-router-tabs-tests.ts"]
"files": ["index.d.ts", "react-router-tabs-tests.tsx"]
}