Skip to content

Commit cdb76e3

Browse files
committed
#204: Correctly infer props from ClassBased Link components
1 parent 36086ba commit cdb76e3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/link.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fr } from "./fr";
33
import { cx } from "./tools/cx";
44
import { assert } from "tsafe/assert";
55
import { is } from "tsafe/is";
6+
import type { UnpackProps } from "./tools/UnpackProps";
67

78
type HTMLAnchorProps = DetailedHTMLProps<
89
AnchorHTMLAttributes<HTMLAnchorElement>,
@@ -12,10 +13,8 @@ type HTMLAnchorProps = DetailedHTMLProps<
1213
// eslint-disable-next-line @typescript-eslint/no-empty-interface
1314
export interface RegisterLink {}
1415

15-
export type RegisteredLinkProps = RegisterLink extends {
16-
Link: (props: infer LinkProps) => any;
17-
}
18-
? Omit<LinkProps, "children">
16+
export type RegisteredLinkProps = RegisterLink extends { Link: infer Link }
17+
? Omit<UnpackProps<Link>, "children">
1918
: Omit<HTMLAnchorProps, "children">;
2019

2120
let Link: (

src/tools/UnpackProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type UnpackProps<T> = T extends React.ComponentType<infer P> ? P : never;

0 commit comments

Comments
 (0)