/* eslint-disable @typescript-eslint/no-explicit-any */ import type { ClassicComponentClass, ComponentClass, ComponentProps, ComponentType, ForwardRefExoticComponent, FunctionComponent, ReactElement, } from "react"; import type { ColorSchemeName, ImageStyle, TextStyle, ViewStyle, } from "react-native"; import type { DotNotation, ResolveDotPath } from "react-native-css/utilities"; /******************************** API ********************************/ export type StyledReactElement< C extends ReactComponent, M extends StyledConfiguration, > = ReactElement< ComponentProps & { [K in keyof M as K extends string ? M[K] extends undefined | false ? never : M[K] extends true | string | object ? K : never : never]?: string; } >; export type StyledProps> = P & { [K in keyof M as K extends string ? M[K] extends undefined | false ? never : M[K] extends true | string | object ? K : never : never]?: string; }; export type Styled = < const C extends ReactComponent, const M extends StyledConfiguration, >( component: C, mapping: M & StyledConfiguration, options?: StyledOptions, ) => StyledComponent; type StyledComponent< C extends ReactComponent, M extends StyledConfiguration, > = ComponentType< ComponentProps & { [K in keyof M as K extends string ? M[K] extends undefined | false ? never : M[K] extends true | string | object ? K : never : never]?: string; } >; export type StyledConfiguration< C extends ReactComponent, K extends string = string, > = Record< K, | boolean | ComponentPropsDotNotation | StyledConfigurationObject | false> >; interface StyledConfigurationObject< C extends ReactComponent, T extends ComponentPropsDotNotation | false, > { target: T; nativeStyleMapping?: T extends false ? NativeStyleMapping> : NativeStyleMapping< ResolveDotPath>, ComponentProps >; /** @deprecated Please use nativeStyleMapping */ nativeStyleToProp?: NativeStyleMapping< ResolveDotPath>, ComponentProps >; } type NativeStyleMapping = T extends object ? { [K in keyof T as K extends string ? K : never]: true | DotNotation; } & { fill?: true | DotNotation; stroke?: true | DotNotation; } : Record>; export interface StyledOptions { passThrough?: boolean; } /*************************** React Helpers ***************************/ export type ReactComponent

= // eslint-disable-next-line @typescript-eslint/no-deprecated | ClassicComponentClass

| ComponentClass

| FunctionComponent

| ForwardRefExoticComponent

; export type ComponentPropsDotNotation = DotNotation< ComponentProps >; /******************************** Styles ********************************/ export type InlineStyleRecord = Record & { // Used to differentiate between InlineStyleRecord and StyleRule s?: never; }; export type InlineStyle = | InlineStyleRecord | undefined | null | (Record | undefined | null)[] | (() => unknown); /********************************* Misc *********************************/ export type Props = Record | undefined | null; export type Callback = () => void; export type RNStyle = ViewStyle & TextStyle & ImageStyle; /******************************** Globals ********************************/ export interface ColorScheme { get: () => ColorSchemeName; set: (value: ColorSchemeName) => void; }