Skip to content

Commit 8c4fe97

Browse files
committed
Got it working!
1 parent 9a8df08 commit 8c4fe97

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/08-advanced-patterns/72.5-as-prop-with-forward-ref.solution.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentPropsWithRef, ElementType, forwardRef, useRef } from "react";
1+
import { ComponentProps, ElementType, forwardRef, useRef } from "react";
22
import { Equal, Expect } from "../helpers/type-utils";
33

44
type FixedForwardRef = <T, P = {}>(
@@ -7,10 +7,20 @@ type FixedForwardRef = <T, P = {}>(
77

88
const fixedForwardRef = forwardRef as FixedForwardRef;
99

10-
function UnwrappedLink<T extends ElementType>(
10+
type DistributiveOmit<T, TOmitted extends PropertyKey> = T extends any
11+
? Omit<T, TOmitted>
12+
: never;
13+
14+
function UnwrappedLink<
15+
T extends ElementType,
16+
Props extends DistributiveOmit<
17+
ComponentProps<ElementType extends T ? "a" : T>,
18+
"as"
19+
>,
20+
>(
1121
props: {
1222
as?: T;
13-
} & Omit<ComponentPropsWithRef<ElementType extends T ? "a" : T>, "as">,
23+
} & Props,
1424
) {
1525
const { as: Comp = "a", ...rest } = props;
1626
return <Comp {...rest}></Comp>;

0 commit comments

Comments
 (0)