Skip to content

Commit

Permalink
argh fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Jun 20, 2019
1 parent 680d5da commit 5d9b686
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion types/example-app/CustomLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface Props {
href: string;
active: boolean;
onClick: (event: React.SyntheticEvent<any>) => void;
children: React.ReactNode;
children?: React.ReactNode;
}

export function CustomLink({ href, active, onClick, children }: Props) {
Expand Down
60 changes: 43 additions & 17 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare module 'found' {
import * as React from 'react';
import { Reducer, Store, StoreEnhancer } from 'redux';

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

interface ObjectMap {
[key: string]: any;
Expand Down Expand Up @@ -342,33 +342,48 @@ declare module 'found' {
onClick?: (event: React.SyntheticEvent<any>) => void;
}

interface LinkInjectedProps {
href: string;
onClick: (event: React.SyntheticEvent<any>) => void;
}

interface LinkPropsNodeChild extends LinkPropsCommon {
activeClassName?: string;
activeStyle?: {};
children?: React.ReactNode;
}

type ReplaceProps<TInner extends React.ElementType, TProps> = Omit<
type ReplaceLinkProps<TInner extends React.ElementType, TProps> = Omit<
React.ComponentProps<TInner>,
keyof TProps
keyof TProps | keyof LinkInjectedProps
> &
TProps;

type LinkPropsSimple = ReplaceProps<'a', LinkPropsNodeChild>;
type LinkPropsSimple = ReplaceLinkProps<'a', LinkPropsNodeChild>;

type LinkPropsWithAs<TInner extends React.ElementType> = ReplaceProps<
type LinkPropsWithAs<
TInner extends React.ElementType<LinkInjectedProps>
> = ReplaceLinkProps<
TInner,
LinkPropsNodeChild & { as: TInner }
LinkPropsNodeChild & {
as: TInner;
activePropName?: null;
}
>;

type LinkPropsWithActivePropName<
TInner extends React.ElementType<
{ [activePropName in TActivePropName]: boolean }
TInner extends React.ComponentType<
LinkInjectedProps & { [activePropName in TActivePropName]: boolean }
>,
TActivePropName extends string
> = ReplaceProps<
> = ReplaceLinkProps<
TInner,
LinkPropsNodeChild & { as: TInner; activePropName: TActivePropName }
LinkPropsNodeChild & {
as: TInner;
activePropName: TActivePropName;
} & {
[activePropName in TActivePropName]?: null;
}
>;

interface LinkPropsWithFunctionChild extends LinkPropsCommon {
Expand All @@ -379,18 +394,29 @@ declare module 'found' {
}) => React.ReactNode;
}

type LinkProps<
TInner extends React.ElementType = never,
TInnerWithActivePropName extends React.ComponentType<
LinkInjectedProps & { [activePropName in TActivePropName]: boolean }
> = never,
TActivePropName extends string = never
> =
| LinkPropsSimple
| LinkPropsWithAs<TInner>
| LinkPropsWithActivePropName<TInnerWithActivePropName, TActivePropName>
| LinkPropsWithFunctionChild;

class Link<
TInner extends React.ElementType = never,
TInnerWithActivePropName extends React.ElementType<
{ [activePropName in TActivePropName]: boolean }
TInnerWithActivePropName extends React.ComponentType<
LinkInjectedProps & { [activePropName in TActivePropName]: boolean }
> = never,
TActivePropName extends string = never
> extends React.Component<
| LinkPropsWithFunctionChild
| LinkPropsWithActivePropName<TInnerWithActivePropName, TActivePropName>
| LinkPropsWithAs<TInner>
| LinkPropsSimple
> {}
LinkProps<TInner, TInnerWithActivePropName, TActivePropName>
> {
props: LinkProps<TInner, TInnerWithActivePropName, TActivePropName>;
}

interface RouterState {
match: Match;
Expand Down

0 comments on commit 5d9b686

Please sign in to comment.