Skip to content

Commit e0d398d

Browse files
committed
remove flatten union
1 parent a2995cc commit e0d398d

File tree

7 files changed

+18
-50
lines changed

7 files changed

+18
-50
lines changed

packages/clerk-js/src/ui/Components.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
ClerkOptions,
1010
CreateOrganizationProps,
1111
EnvironmentResource,
12-
FlattenUnionType,
1312
GoogleOneTapProps,
1413
OrganizationProfileProps,
1514
SignInProps,
@@ -113,7 +112,7 @@ export type ComponentControls = {
113112
props: T extends 'checkout'
114113
? __internal_CheckoutProps
115114
: T extends 'planDetails'
116-
? FlattenUnionType<__internal_PlanDetailsProps>
115+
? __internal_PlanDetailsProps
117116
: T extends 'subscriptionDetails'
118117
? __internal_SubscriptionDetailsProps
119118
: never,
@@ -162,7 +161,7 @@ interface ComponentsState {
162161
};
163162
planDetailsDrawer: {
164163
open: false;
165-
props: null | FlattenUnionType<__internal_PlanDetailsProps>;
164+
props: null | __internal_PlanDetailsProps;
166165
};
167166
subscriptionDetailsDrawer: {
168167
open: false;

packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
ClerkAPIResponseError,
55
CommercePlanResource,
66
CommerceSubscriptionPlanPeriod,
7-
FlattenUnionType,
87
} from '@clerk/types';
98
import * as React from 'react';
109
import { useMemo, useState } from 'react';
@@ -29,7 +28,7 @@ import {
2928
useLocalizations,
3029
} from '../../customizables';
3130

32-
export const PlanDetails = (props: FlattenUnionType<__internal_PlanDetailsProps>) => {
31+
export const PlanDetails = (props: __internal_PlanDetailsProps) => {
3332
return (
3433
<Drawer.Content>
3534
<PlanDetailsInternal {...props} />
@@ -74,7 +73,7 @@ const PlanDetailsInternal = ({
7473
planId,
7574
plan: initialPlan,
7675
initialPlanPeriod = 'month',
77-
}: FlattenUnionType<__internal_PlanDetailsProps>) => {
76+
}: __internal_PlanDetailsProps) => {
7877
const clerk = useClerk();
7978
const [planPeriod, setPlanPeriod] = useState<CommerceSubscriptionPlanPeriod>(initialPlanPeriod);
8079

packages/clerk-js/src/ui/lazyModules/MountedPlanDetailDrawer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useUser } from '@clerk/shared/react';
2-
import type { __internal_PlanDetailsProps, Appearance, FlattenUnionType } from '@clerk/types';
2+
import type { __internal_PlanDetailsProps, Appearance } from '@clerk/types';
33

44
import { PlanDetails } from './components';
55
import { LazyDrawerRenderer } from './providers';
@@ -13,7 +13,7 @@ export function MountedPlanDetailDrawer({
1313
onOpenChange: (open: boolean) => void;
1414
planDetailsDrawer: {
1515
open: false;
16-
props: null | FlattenUnionType<__internal_PlanDetailsProps>;
16+
props: null | __internal_PlanDetailsProps;
1717
};
1818
}) {
1919
const { user } = useUser();

packages/clerk-js/src/ui/lazyModules/providers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const LazyComponentRenderer = (props: LazyComponentRendererProps) => {
7676
>
7777
<Portal
7878
node={props.node}
79-
component={ClerkComponents[props.componentName as ClerkComponentName]}
79+
component={ClerkComponents[props.componentName as ClerkComponentName] as React.ComponentType<any>}
8080
props={props.componentProps}
8181
componentName={props.componentName}
8282
/>

packages/react/src/components/PlanDetailsButton.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@ import { withClerk } from './withClerk';
3535
*/
3636
export const PlanDetailsButton = withClerk(
3737
({ clerk, children, ...props }: WithClerkProp<React.PropsWithChildren<__experimental_PlanDetailsButtonProps>>) => {
38-
const { plan, planId, initialPlanPeriod, planDetailsProps, ...rest } = props as any;
39-
40-
const planDetails = {
41-
plan,
42-
planId,
43-
initialPlanPeriod,
44-
...planDetailsProps,
45-
} as __experimental_PlanDetailsButtonProps;
38+
const { plan, planId, initialPlanPeriod, planDetailsProps, ...rest } = props;
4639

4740
children = normalizeWithDefaultValue(children, 'Plan details');
4841
const child = assertSingleChild(children)('PlanDetailsButton');
@@ -52,7 +45,12 @@ export const PlanDetailsButton = withClerk(
5245
return;
5346
}
5447

55-
return clerk.__internal_openPlanDetails(planDetails);
48+
return clerk.__internal_openPlanDetails({
49+
plan,
50+
planId,
51+
initialPlanPeriod,
52+
...planDetailsProps,
53+
} as __experimental_PlanDetailsButtonProps);
5654
};
5755

5856
const wrappedChildClickHandler: React.MouseEventHandler = async e => {

packages/types/src/clerk.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,12 +1889,14 @@ export type __experimental_CheckoutButtonProps = {
18891889
export type __internal_PlanDetailsProps = (
18901890
| {
18911891
planId: string;
1892+
plan?: never;
18921893
}
18931894
| {
18941895
/**
18951896
* The plan object will be used as initial data until the plan is fetched from the server.
18961897
*/
18971898
plan: CommercePlanResource;
1899+
planId?: never;
18981900
}
18991901
) & {
19001902
appearance?: PlanDetailTheme;
@@ -1916,12 +1918,14 @@ export type __internal_PlanDetailsProps = (
19161918
export type __experimental_PlanDetailsButtonProps = (
19171919
| {
19181920
planId: string;
1921+
plan?: never;
19191922
}
19201923
| {
19211924
/**
19221925
* The plan object will be used as initial data until the plan is fetched from the server.
19231926
*/
19241927
plan: CommercePlanResource;
1928+
planId?: never;
19251929
}
19261930
) & {
19271931
initialPlanPeriod?: CommerceSubscriptionPlanPeriod;

packages/types/src/utils.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -113,35 +113,3 @@ export type Without<T, W> = {
113113
* Value contains: { a:string, b: string }
114114
*/
115115
export type Override<T, U> = Omit<T, keyof U> & U;
116-
117-
// Converts a union of two types into an intersection
118-
// i.e. A | B -> A & B
119-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
120-
121-
type FlattenUnionTypeInternal<T> = {
122-
[K in keyof UnionToIntersection<T>]: K extends keyof T
123-
? T[K] extends any[]
124-
? T[K]
125-
: T[K] extends object
126-
? FlattenUnionType<T[K]>
127-
: T[K]
128-
: UnionToIntersection<T>[K] | undefined;
129-
};
130-
131-
// Convert properties with `| undefined` to optional properties
132-
type UndefinedToOptional<T> = {
133-
[K in keyof T as undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>;
134-
} & {
135-
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
136-
};
137-
138-
/**
139-
* Flattens a union type into a single type with all properties, making union properties optional.
140-
*
141-
* @example
142-
* type A = { a: number; c: number };
143-
* type B = { b: string; c: number };
144-
* type Result = FlattenUnionType<A | B>;
145-
* // Result: { a?: number; b?: string; c: number }
146-
*/
147-
export type FlattenUnionType<T> = UndefinedToOptional<FlattenUnionTypeInternal<T>>;

0 commit comments

Comments
 (0)