diff --git a/packages/vkui/src/components/DatePicker/DatePicker.tsx b/packages/vkui/src/components/DatePicker/DatePicker.tsx index bb96371991..47cda2a9c2 100644 --- a/packages/vkui/src/components/DatePicker/DatePicker.tsx +++ b/packages/vkui/src/components/DatePicker/DatePicker.tsx @@ -2,9 +2,9 @@ import * as React from 'react'; import { leadingZero } from '@vkontakte/vkjs'; import { range } from '../../helpers/range'; import { useAdaptivityHasPointer } from '../../hooks/useAdaptivityHasPointer'; -import { HTMLAttributesWithRootRef } from '../../types'; +import { HasOnlyExpectedProps, HTMLAttributesWithRootRef } from '../../types'; import { CustomSelect } from '../CustomSelect/CustomSelect'; -import { Input } from '../Input/Input'; +import { Input, type InputProps } from '../Input/Input'; import { RootComponent } from '../RootComponent/RootComponent'; import styles from './DatePicker.module.css'; @@ -167,9 +167,10 @@ const DatePickerNative = ({ }, [onDateChange], ); + const inputProps: HasOnlyExpectedProps = restProps; return ( ({ dropdownOffsetDistance, dropdownAutoWidth, forceDropdownPortal, - selectType, noMaxHeight, autoHideScrollbar, autoHideScrollbarDelay, labelTextTestId, nativeSelectTestId, - ...nativeProps // TODO: https://github.com/Microsoft/TypeScript/issues/12936 + after, + mode, + ...restProps } = props; const hasPointer = useAdaptivityHasPointer(); + const nativeProps: HasOnlyExpectedProps = restProps; + return ( {(hasPointer === undefined || hasPointer) && } diff --git a/packages/vkui/src/types.ts b/packages/vkui/src/types.ts index deba74d767..8be598ae14 100644 --- a/packages/vkui/src/types.ts +++ b/packages/vkui/src/types.ts @@ -89,3 +89,40 @@ export type GetPropsWithFunctionKeys = { }[keyof T]; export type PickOnlyFunctionProps = Pick>; + +/** + * Даёт возможность поймать ошибку, если в компонент передаются лишние свойства. + * + * @example + * // пример использования + * const nativeProps: HasOnlyExpectedProps = restProps; + * + * @example + * // расширенный пример + * type SelectProps { + * mode: string, + * multiline: boolean; + * selectType?: SelectType; + * } + * + * type NativeSelectProps { + * selectType?: SelectType; + * } + * + * const selectProps: SelectProps = { + * mode: "card", + * multiline: true, + * selectType: "default", + * } + * + * // будет ошибка, так как multiline в NativeSelectProps нет + * const {mode, ...restProps} = selectProps; + * const nativeProps: HasOnlyExpectedProps = restProps; + * + * // а вот так ошибки не будет, так как restProps больше не содержит multiline + * const {mode, multiline, ...restProps} = selectProps; + * const nativeProps: HasOnlyExpectedProps = restProps; + */ +export type HasOnlyExpectedProps = { + [K in keyof Props]: K extends keyof ExpectedProps ? ExpectedProps[K] : never; +};