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 cdb76e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 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,10 +13,8 @@ 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">
export type RegisteredLinkProps = RegisterLink extends { Link: infer Link }
? Omit<UnpackProps<Link>, "children">
: Omit<HTMLAnchorProps, "children">;

let Link: (
Expand Down
1 change: 1 addition & 0 deletions src/tools/UnpackProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type UnpackProps<T> = T extends React.ComponentType<infer P> ? P : never;

0 comments on commit cdb76e3

Please sign in to comment.