Skip to content

Commit 78f92c6

Browse files
committed
Patch: Removed ts-toolbelt dep
1 parent f610bf7 commit 78f92c6

5 files changed

Lines changed: 1579 additions & 7866 deletions

File tree

packages/react-slots/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,5 @@
4444
"react-dom": {
4545
"optional": true
4646
}
47-
},
48-
"dependencies": {
49-
"ts-toolbelt": "^9.6.0"
5047
}
5148
}

packages/react-slots/src/OverrideNode.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from "react";
2-
import { type Any } from "ts-toolbelt";
3-
import { Function } from "ts-toolbelt";
42
import { forEachNode, forEachNodeReplace } from "./forEachNode";
3+
import { NoInfer, Pretty } from "./typeUtils";
54

65
type AllowedNodes = React.ElementType | StringConstructor | NumberConstructor;
76

@@ -27,7 +26,7 @@ type OverrideNodeProps<
2726
T extends AllowedNodes,
2827
U extends "throw" | "ignore" | "remove" = "throw",
2928
TNode = GetNode<T>,
30-
TProps = Any.Compute<GetProps<T>, "flat">,
29+
TProps = Pretty<GetProps<T>>,
3130
> = {
3231
/**
3332
* An array specifying allowed React intrinsic element names or custom component names.
@@ -92,14 +91,14 @@ export type OverrideNode = {
9291
| (null extends T ? null : never);
9392
/** Intercepts a call to a prop and executes the x function before the original function. */
9493
chainBefore: <T extends (...args: any[]) => any>(
95-
x: Function.NoInfer<T>,
94+
x: NoInfer<T>,
9695
) => (prop: T, propName: keyof any, slotName: string) => T;
9796
/** Intercepts a call to a prop and executes the x function after the original function. */
9897
chainAfter: <T extends (...args: any[]) => any>(
99-
x: Function.NoInfer<T>,
98+
x: NoInfer<T>,
10099
) => (prop: T, propName: keyof any, slotName: string) => T;
101100
/** Overrides prop */
102-
override: <T>(x: Function.NoInfer<T>) => (prop: T) => T;
101+
override: <T>(x: NoInfer<T>) => (prop: T) => T;
103102
};
104103

105104
export const OverrideNode = (() => {
@@ -373,7 +372,7 @@ export function applyOverride(
373372
if (typeof currentConfig.props === "function") {
374373
newChild = React.cloneElement(
375374
newChild,
376-
currentConfig.props(newChild.props),
375+
currentConfig.props(newChild.props as any),
377376
);
378377
} else if (
379378
typeof currentConfig.props === "object" &&
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export type UnionToIntersection<U> = (
2+
U extends any ? (k: U) => void : never
3+
) extends (k: infer I) => void
4+
? I
5+
: never;
6+
7+
export type Pretty<T> = {
8+
[K in keyof T]: T[K];
9+
} & {};
10+
11+
export type NoInfer<T> = [T][T extends any ? 0 : never];

packages/react-slots/src/types.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from "react";
2-
import { Any } from "ts-toolbelt";
32
import {
43
COMPONENT_TYPE,
54
DEFAULT_TEMPLATE_AS,
@@ -8,19 +7,14 @@ import {
87
SLOT_TYPE_IDENTIFIER,
98
type DefaultSlotName,
109
} from "./constants";
10+
import { Pretty, UnionToIntersection } from "./typeUtils";
1111

1212
// Note on {} vs object in type args.
1313
// We like to write `extends object` whenever a type is exported because it's
1414
// bit more stricter to what can actually be assigned to it.
1515
// For utility types that don't get exported but are used by other types,
1616
// we prefer {} because it looks cleaner on hover
1717

18-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
19-
k: infer I,
20-
) => void
21-
? I
22-
: never;
23-
2418
type ElementType =
2519
| Exclude<React.ComponentType<any>, SlotComponent<any>>
2620
| Exclude<React.ElementType, React.ComponentType<any>>;
@@ -220,11 +214,10 @@ type GetTemplateUnions<U> = U extends TemplateAsSlotComponentLikeElement<
220214
/**
221215
* Create type-safe template
222216
*/
223-
export type CreateTemplate<T extends SlotChildren> = {} & Any.Compute<
217+
export type CreateTemplate<T extends SlotChildren> = Pretty<
224218
UnionToIntersection<
225219
GetTemplateUnions<Exclude<0 extends T & 1 ? SlotChildren : T, undefined>>
226-
>,
227-
"flat"
220+
>
228221
>;
229222

230223
// ------------------ //
@@ -266,18 +259,17 @@ type GetSlotComponentUnions<T> = T extends TemplateAsSlotComponentLikeElement<
266259
? { [Name in N]: SlotComponent<P> }
267260
: never;
268261

269-
type CreateSlotComponent<T extends SlotChildren> = {} & Any.Compute<
262+
type CreateSlotComponent<T extends SlotChildren> = {} & Pretty<
270263
UnionToIntersection<
271264
GetSlotComponentUnions<0 extends T & 1 ? SlotChildren : T>
272-
>,
273-
"flat"
265+
>
274266
>;
275267

276268
export type CreateSlot<T extends SlotChildren> = CreateSlotComponent<T>;
277269

278270
// -------------------- //
279271

280-
export type HasSlot<T extends SlotChildren> = Any.Compute<{
272+
export type HasSlot<T extends SlotChildren> = Pretty<{
281273
[Name in Extract<
282274
T,
283275
React.ReactElement<{ "slot-name": string }>

0 commit comments

Comments
 (0)