Skip to content

Commit 8117e6d

Browse files
Fix TypeScript compilation errors
- Add React import and forwardRef to Button component to support ref prop - Fix debounce function type issues with proper type assertions - Fix use-debounce-callback hook type definitions - Fix debounced-input component to work with updated debounce function signature These changes resolve the TypeScript compilation errors that were causing the test suite to fail.
1 parent c1c6e06 commit 8117e6d

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

packages/components/src/ui/button.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Slot } from '@radix-ui/react-slot';
22
import { type VariantProps, cva } from 'class-variance-authority';
3-
import type { ButtonHTMLAttributes } from 'react';
3+
import React, { type ButtonHTMLAttributes } from 'react';
44
import { cn } from './utils';
55

66
const buttonVariants = cva(
@@ -35,10 +35,12 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, Va
3535
asChild?: boolean;
3636
}
3737

38-
export function Button({ className, variant, size, asChild = false, ...props }: ButtonProps) {
39-
const Comp = asChild ? Slot : 'button';
40-
return <Comp className={cn(buttonVariants({ variant, size, className }))} data-slot="button" {...props} />;
41-
}
38+
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
39+
({ className, variant, size, asChild = false, ...props }, ref) => {
40+
const Comp = asChild ? Slot : 'button';
41+
return <Comp ref={ref} className={cn(buttonVariants({ variant, size, className }))} data-slot="button" {...props} />;
42+
}
43+
);
4244

4345
Button.displayName = 'Button';
4446

packages/components/src/ui/data-table-filter/hooks/use-debounce-callback.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ type ControlFunctions = {
1414
isPending: () => boolean;
1515
};
1616

17-
export type DebouncedState<T extends (...args: any) => ReturnType<T>> = ((
17+
export type DebouncedState<T extends (...args: any) => any> = ((
1818
...args: Parameters<T>
1919
) => ReturnType<T> | undefined) &
2020
ControlFunctions;
2121

22-
export function useDebounceCallback<T extends (...args: any) => ReturnType<T>>(
22+
export function useDebounceCallback<T extends (...args: any) => any>(
2323
func: T,
2424
delay = 500,
2525
options?: DebounceOptions,
2626
): DebouncedState<T> {
27-
const debouncedFunc = useRef<ReturnType<typeof debounce>>(null);
27+
const debouncedFunc = useRef<ReturnType<typeof debounce> | null>(null);
2828

2929
useUnmount(() => {
3030
if (debouncedFunc.current) {

packages/components/src/ui/data-table-filter/lib/debounce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function debounce<T extends (...args: unknown[]) => unknown>(
3232
lastArgs = null;
3333
lastThis = null;
3434
lastInvokeTime = time;
35-
result = func.apply(thisArg, args);
35+
result = func.apply(thisArg, args) as ReturnType<T>;
3636
return result;
3737
}
3838

packages/components/src/ui/debounced-input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export function DebouncedInput({
2222
// Define the debounced function with useCallback
2323
// biome-ignore lint/correctness/useExhaustiveDependencies: from Bazza UI
2424
const debouncedOnChange = useCallback(
25-
debounce((newValue: string | number) => {
25+
debounce((...args: unknown[]) => {
26+
const newValue = args[0] as string | number;
2627
onChange(newValue);
2728
}, debounceMs), // Pass the wait time here
2829
[debounceMs, onChange], // Dependencies

0 commit comments

Comments
 (0)