Skip to content

Commit 2d3e69a

Browse files
fix: enhance UnwrapRecursiveArray to support maximum depth limit (#195)
* fix: enhance UnwrapRecursiveArray to support maximum depth limit * chore: use ComponentPropsWithRef in styled utility * Apply suggestions from code review --------- Co-authored-by: Mark Lawlor <[email protected]>
1 parent c63f936 commit 2d3e69a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/utilities/dot-notation.types.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ export type StyleProp<T> =
2929
// ---------- Type Helpers ----------
3030

3131
// Unwrap nested arrays (from RecursiveArray)
32-
type UnwrapRecursiveArray<T> = T extends (infer I)[]
33-
? UnwrapRecursiveArray<I>
34-
: T;
32+
type UnwrapRecursiveArray<
33+
T,
34+
Depth extends unknown[] = [],
35+
MaxDepth extends number = 10
36+
> = Depth["length"] extends MaxDepth
37+
? T
38+
: T extends (infer I)[]
39+
? UnwrapRecursiveArray<I, [...Depth, unknown], MaxDepth>
40+
: T;
41+
3542

3643
// Remove null, false, undefined, etc.
3744
type RemoveFalsy<T> = Exclude<T, Falsy>;

src/web/api.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
createElement,
33
useMemo,
4-
type ComponentProps,
4+
type ComponentPropsWithRef,
55
type PropsWithChildren,
66
} from "react";
77
import { Appearance } from "react-native";
@@ -25,7 +25,7 @@ export const styled = <
2525
mapping: M,
2626
_options?: StyledOptions,
2727
) => {
28-
return (props: StyledProps<ComponentProps<C>, M>) => {
28+
return (props: StyledProps<ComponentPropsWithRef<C>, M>) => {
2929
return useCssElement(baseComponent, mapping, props);
3030
};
3131
};

0 commit comments

Comments
 (0)