Skip to content

Commit

Permalink
fix: Builder type (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Dec 4, 2023
1 parent 71571e7 commit b0a7dfb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-phones-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: Update `Builder` type to support all Melt UI builders
1 change: 1 addition & 0 deletions src/lib/bits/calendar/components/calendar-date.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const attrs = getAttrs("date");
$: builder = $cell(date, month);
$: Object.assign(builder, attrs);
const dispatch = createDispatcher();
Expand Down
15 changes: 9 additions & 6 deletions src/lib/helpers/builders.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Action, ActionReturn } from "svelte/action";

export type Builder = {
[x: PropertyKey]: unknown;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
action: Action<HTMLElement, any, any>;
export type Builder<
Element = any,
Param = any,
Attributes extends Record<string, any> = Record<string, any>
> = Record<string, any> & {
action: Action<Element, Param, Attributes>;
};

type BuilderActionsParams = {
builders: Builder[];
builders: Builder<any, any, any>[];
};

type BuilderActionsReturn = {
Expand Down Expand Up @@ -36,7 +39,7 @@ export function builderActions(
};
}

export function getAttrs(builders: Builder[]) {
export function getAttrs(builders: Builder<any, any, any>[]) {
const attrs: Record<string, unknown | undefined> = {};
builders.forEach((builder) => {
Object.keys(builder).forEach((key) => {
Expand Down

0 comments on commit b0a7dfb

Please sign in to comment.