Skip to content

Commit

Permalink
#204: Correctly infer props from ClassBased Link components
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Oct 31, 2023
1 parent 36086ba commit b6f3636
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fr } from "./fr";
import { cx } from "./tools/cx";
import { assert } from "tsafe/assert";
import { is } from "tsafe/is";
import type { UnpackProps } from "./tools/UnpackProps";

type HTMLAnchorProps = DetailedHTMLProps<
AnchorHTMLAttributes<HTMLAnchorElement>,
Expand All @@ -12,11 +13,7 @@ type HTMLAnchorProps = DetailedHTMLProps<
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RegisterLink {}

export type RegisteredLinkProps = RegisterLink extends {
Link: (props: infer LinkProps) => any;
}
? Omit<LinkProps, "children">
: Omit<HTMLAnchorProps, "children">;
export type RegisteredLinkProps = RegisterLink extends { Link: infer Link; } ? Omit<UnpackProps<Link>, "children"> : Omit<HTMLAnchorProps, "children">;

let Link: (
props: RegisteredLinkProps & { children: ReactNode }
Expand Down
5 changes: 5 additions & 0 deletions src/tools/UnpackProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export type UnpackProps<T> = T extends React.ComponentType<infer P>
? P
: never;

0 comments on commit b6f3636

Please sign in to comment.