refactor: improve type safety (#5539)

* refactor(popover): consolidate imports from aria-utils module

* refactor(popover): remove unnecessary type assertion for child ref

* refactor: remove unnecessary type assertions and improve type safety

* chore(changeset): add changeset
This commit is contained in:
luis angel lopez huari 2025-08-31 07:22:47 -05:00 committed by GitHub
parent 8eb269df9e
commit e2aed2e946
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 19 additions and 10 deletions

View File

@ -0,0 +1,10 @@
---
"@heroui/use-aria-accordion-item": patch
"@heroui/date-picker": patch
"@heroui/shared-utils": patch
"@heroui/test-utils": patch
"@heroui/popover": patch
"@heroui/form": patch
---
Code quality improvements: removed unnecessary type assertions across multiple components and utilities, consolidated imports in Popover module, and enhanced type safety.

View File

@ -206,7 +206,7 @@ export const useSandpack = ({
"react": "18.3.1",
"react-dom": "18.3.1",
${Object.entries(
omit(dependencies as any, [
omit(dependencies, [
"react",
"react-dom",
"react-dom/client",

View File

@ -169,7 +169,7 @@ export function useDatePickerBase<T extends DateValue>(originalProps: UseDatePic
const disableAnimation =
originalProps.disableAnimation ?? globalContext?.disableAnimation ?? false;
let stringFormatter = useLocalizedStringFormatter(intlMessages) as any;
let stringFormatter = useLocalizedStringFormatter(intlMessages);
const isDefaultColor = originalProps.color === "default" || !originalProps.color;
const hasMultipleMonths = visibleMonths > 1;

View File

@ -136,7 +136,7 @@ export function useContextProps<T, U extends SlotProps, E extends Element>(
): [T, RefObject<E | null>] {
let ctx = useSlottedContext(context, props.slot) || {};
// @ts-ignore - TS says "Type 'unique symbol' cannot be used as an index type." but not sure why.
let {ref: contextRef, ...contextProps} = ctx as any;
let {ref: contextRef, ...contextProps} = ctx;
let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));
let mergedProps = mergeProps(contextProps, props) as unknown as T;

View File

@ -32,7 +32,7 @@ const PopoverTrigger = (props: PopoverTriggerProps) => {
// Accessing the ref from props, else fallback to element.ref
// https://github.com/facebook/react/pull/28348
const childRef = child.props.ref ?? (child as any).ref;
const childRef = child.props.ref ?? child.ref;
const {onPress, isDisabled, ...restProps} = useMemo(() => {
return getTriggerProps(mergeProps(otherProps, child.props), childRef);

View File

@ -13,9 +13,8 @@ import {useDOMRef} from "@heroui/react-utils";
import {useOverlayTriggerState} from "@react-stately/overlays";
import {useFocusRing} from "@react-aria/focus";
import {useOverlayTrigger, usePreventScroll} from "@react-aria/overlays";
import {getShouldUseAxisPlacement} from "@heroui/aria-utils";
import {getShouldUseAxisPlacement, getArrowPlacement} from "@heroui/aria-utils";
import {mapPropsVariants, useProviderContext} from "@heroui/system";
import {getArrowPlacement} from "@heroui/aria-utils";
import {popover} from "@heroui/theme";
import {clsx, dataAttr, objectToDeps, mergeProps, mergeRefs} from "@heroui/shared-utils";
import {useMemo, useCallback, useRef} from "react";

View File

@ -49,7 +49,7 @@ export function useAriaAccordionItem<T>(
if (!manager.canSelectItem(key)) {
return;
}
manager.select(key, e as any);
manager.select(key, e);
state.toggleKey(key);
},
[key, manager],

View File

@ -353,9 +353,9 @@ export const intersectionBy = <T>(...args: [...arrays: T[][], iteratee: Iteratee
const getIterateeValue = (item: T): unknown => {
if (typeof iteratee === "function") {
return (iteratee as (value: T) => any)(item);
return iteratee(item);
} else if (typeof iteratee === "string") {
return (item as any)[iteratee];
return item[iteratee];
} else {
throw new Error("Iteratee must be a function or a string key of the array elements");
}

View File

@ -22,7 +22,7 @@ export function mockImage() {
return name in this;
}
getAttribute(name: string) {
return name in this ? (this as any)[name] : null;
return name in this ? this[name] : null;
}
constructor() {
setTimeout(() => {