Skip to content

Commit

Permalink
Fix deep expanding types causing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jeannemas committed Apr 16, 2024
1 parent 4b56bb0 commit 03163f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-boxes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jeanne-mas/svelte-ui': patch
---

Fixed deep expanding types causing issues
12 changes: 4 additions & 8 deletions src/lib/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ export type Transition = (node: Element, params?: unknown) => TransitionConfig;
export type TransitionParams<T extends Transition> = Parameters<T>[1];

/**
* Recursively expands the type of an object.
* Expands the type of an object.
*/
type ExpandDeep<T> = T extends object
? T extends infer O
? { [K in keyof O]: ExpandDeep<O[K]> }
: never
: T;
type Expand<T> = T extends object ? (T extends infer O ? { [K in keyof O]: O[K] } : never) : T;
/**
* Fix for the following error:
*
Expand All @@ -26,9 +22,9 @@ type ExpandDeep<T> = T extends object
*/
type PatchSlotsWithBuilderAction<TSlots extends Record<string, Record<string, unknown>>> = {
[TSlotName in keyof TSlots]: TSlots[TSlotName] extends { builder: infer TBuilder }
? ExpandDeep<Omit<TSlots[TSlotName], 'builder'>> & {
? Expand<Omit<TSlots[TSlotName], 'builder'>> & {
builder: TBuilder extends { action: Action }
? ExpandDeep<Omit<TBuilder, 'action'>> & {
? Expand<Omit<TBuilder, 'action'>> & {
action: Action;
}
: TBuilder;
Expand Down

0 comments on commit 03163f8

Please sign in to comment.