// Definitions by: Pat Sissons // TypeScript Version: 3.4 import { Theme } from '@emotion/react' import * as RN from 'react-native' type ReactNative = typeof RN export type ReactNativeStyle = RN.ViewStyle | RN.TextStyle | RN.ImageStyle export type ReactNativeStyleType = Props extends { style?: RN.StyleProp } ? StyleType extends ReactNativeStyle ? StyleType : ReactNativeStyle : ReactNativeStyle export type InterpolationPrimitive< StyleType extends ReactNativeStyle = ReactNativeStyle > = | null | undefined | boolean | number | string | ObjectInterpolation export type ObjectInterpolation< StyleType extends ReactNativeStyle = ReactNativeStyle > = StyleType export interface ArrayCSSInterpolation< StyleType extends ReactNativeStyle = ReactNativeStyle > extends Array> {} export type CSSInterpolation< StyleType extends ReactNativeStyle = ReactNativeStyle > = InterpolationPrimitive | ArrayCSSInterpolation export interface ArrayInterpolation< MergedProps, StyleType extends ReactNativeStyle = ReactNativeStyle > extends Array> {} export interface FunctionInterpolation< MergedProps, StyleType extends ReactNativeStyle = ReactNativeStyle > { (mergedProps: MergedProps): Interpolation } export type Interpolation< MergedProps = unknown, StyleType extends ReactNativeStyle = ReactNativeStyle > = | InterpolationPrimitive | ArrayInterpolation | FunctionInterpolation /** Same as StyledOptions but shouldForwardProp must be a type guard */ export interface FilteringStyledOptions< Props = Record, ForwardedProps extends keyof Props & string = keyof Props & string > { shouldForwardProp?: (propName: string) => propName is ForwardedProps } export interface StyledOptions> { shouldForwardProp?: (propName: string) => boolean } /** * @typeparam ComponentProps Props which will be included when withComponent is called * @typeparam SpecificComponentProps Props which will *not* be included when withComponent is called */ export interface StyledComponent< ComponentProps extends {}, SpecificComponentProps extends {} = {}, JSXProps extends {} = {} > extends React.FC { withComponent>>( component: C ): StyledComponent< ComponentProps & React.ComponentProps, {}, { ref?: React.Ref> } > withComponent>>( component: C ): StyledComponent> } /** * @typeparam ComponentProps Props which will be included when withComponent is called * @typeparam SpecificComponentProps Props which will *not* be included when withComponent is called */ export interface CreateStyledComponent< ComponentProps extends {}, SpecificComponentProps extends {} = {}, JSXProps extends {} = {}, StyleType extends ReactNativeStyle = ReactNativeStyle > { /** * @typeparam AdditionalProps Additional props to add to your styled component */ ( ...styles: ArrayInterpolation< ComponentProps & SpecificComponentProps & AdditionalProps & { theme: Theme }, StyleType > ): StyledComponent< ComponentProps & AdditionalProps, SpecificComponentProps, JSXProps > /** * @typeparam AdditionalProps Additional props to add to your styled component */ ( template: TemplateStringsArray, ...styles: ArrayInterpolation< ComponentProps & SpecificComponentProps & AdditionalProps & { theme: Theme }, StyleType > ): StyledComponent< ComponentProps & AdditionalProps, SpecificComponentProps, JSXProps > } /** * @desc * This function accepts a React component. * * @example styled(MyComponent)({ width: 100 }) * @example styled(MyComponent)(myComponentProps => ({ width: myComponentProps.width }) * @example styled(View)({ width: 100 }) * @example styled(View)(props => ({ width: props.width }) */ export interface CreateStyled { < C extends React.ComponentClass>, ForwardedProps extends keyof React.ComponentProps & string = keyof React.ComponentProps & string >( component: C, options: FilteringStyledOptions, ForwardedProps> ): CreateStyledComponent< Pick, ForwardedProps> & { theme?: Theme as?: React.ElementType }, {}, { ref?: React.Ref> }, ReactNativeStyleType> > >>( component: C, options?: StyledOptions> ): CreateStyledComponent< React.ComponentProps & { theme?: Theme as?: React.ElementType }, {}, { ref?: React.Ref> }, ReactNativeStyleType> > < C extends React.ComponentType>, ForwardedProps extends keyof React.ComponentProps & string = keyof React.ComponentProps & string >( component: C, options: FilteringStyledOptions, ForwardedProps> ): CreateStyledComponent< Pick, ForwardedProps> & { theme?: Theme as?: React.ElementType }, {}, {}, ReactNativeStyleType> > >>( component: C, options?: StyledOptions> ): CreateStyledComponent< React.ComponentProps & { theme?: Theme; as?: React.ElementType }, {}, {}, ReactNativeStyleType> > } export const styled: CreateStyled