import type * as React from 'react'; import type { PlatformType } from './lib/platform'; export type AnyFunction = (...args: any[]) => any; export type AlignType = 'left' | 'center' | 'right'; export interface HasChildren { children?: React.ReactNode | undefined; } export type HasDataAttribute = Record< `data-${string}`, string | number | boolean | undefined | null >; export interface HasRootRef { getRootRef?: React.Ref | undefined; } export interface HasRef { getRef?: React.Ref | undefined; } export interface HasComponent { Component?: React.ElementType | undefined; } export interface HasAlign { align?: AlignType | undefined; } export interface HasPlatform { /** * @ignore */ platform?: PlatformType | undefined; } export interface Version { major: number; minor?: number | undefined; patch?: number | undefined; } /** * Тип содержит атрибуты, которые применяются только для `` * * @see {@link https://developer.mozilla.org/ru/docs/Web/HTML/Element/A <a> - HTML | MDN} */ export type AnchorHTMLAttributesOnly = Omit< React.AnchorHTMLAttributes, keyof React.HTMLAttributes > & React.AriaAttributes; /** * Проверяет, является ли тип подтипом другого. * * В TS не реализовано. * * @see {@link https://github.com/microsoft/TypeScript/issues/12936} */ export type Exact = A extends B ? B : never; /** * Для возможности указывать css custom properties */ export type CSSCustomProperties = Record< `--${string}`, T >; // eslint-disable-next-line @typescript-eslint/no-empty-interface interface Nothing {} /** * Автозаполнение для типов * * @example * LiteralUnion<'foo' | 'bar', string> * * @see {@link https://github.com/microsoft/TypeScript/issues/29729} */ export type LiteralUnion = Union | (Type & Nothing); export type HTMLAttributesWithRootRef = React.HTMLAttributes & HasRootRef; export type ValuesOfObject = T[keyof T]; export type GetPropsWithFunctionKeys = { [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never; }[keyof T]; export type PickOnlyFunctionProps = Pick>; /** * Даёт возможность поймать ошибку, если в компонент передаются лишние свойства. * * @example * // пример использования * const nativeProps: HasOnlyExpectedProps = restProps; * * @example * // расширенный пример * type SelectProps { * mode: string, * multiline: boolean; * selectType?: SelectType | undefined; * } * * type NativeSelectProps { * selectType?: SelectType | undefined; * } * * 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; }; export type TimeoutId = ReturnType | null; export type PartialFields = Omit & Partial>; export type RequiredFields = Omit & Required>; export type Elevation = '1' | '2' | '3' | '4'; /** * Аналог Partial, но с явным | undefined для поддержки exactOptionalPropertyTypes. * Используйте вместо Partial когда нужно поддержать exactOptionalPropertyTypes. */ export type PartialWithUndefined = { [P in keyof T]?: T[P] | undefined; };