Skip to content

Commit

Permalink
Return the correct type
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoufal Elyoussoufi committed Apr 18, 2022
1 parent 3d60ee3 commit 64427ba
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/createText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {ComponentType, ForwardRefExoticComponent} from 'react';
import {
ComponentType,
ForwardRefExoticComponent,
PropsWithoutRef,
RefAttributes,
} from 'react';
import {StyleProp, Text, TextProps as RNTextProps} from 'react-native';

import createRestyleComponent from './createRestyleComponent';
Expand Down Expand Up @@ -49,31 +54,39 @@ export const textRestyleFunctions = [

function createText<
Theme extends BaseTheme,
Props extends Record<string, any> & {style: StyleProp<RNTextProps>},
Props extends Record<string, any> & {style?: StyleProp<RNTextProps>},
EnableShorthand extends boolean = true,
OptionalStyleProp extends boolean = true
>(
BaseComponent: ComponentType<Props>,
): ForwardRefExoticComponent<
Optional<Props, 'style', OptionalStyleProp> &
TextProps<Theme, EnableShorthand>
PropsWithoutRef<
Optional<Props, 'style', OptionalStyleProp> &
TextProps<Theme, EnableShorthand>
> &
RefAttributes<{}>
>;

function createText<
Theme extends BaseTheme,
Props extends RNTextProps = RNTextProps,
EnableShorthand extends boolean = true
>(): ForwardRefExoticComponent<Props & TextProps<Theme, EnableShorthand>>;
>(): ForwardRefExoticComponent<
PropsWithoutRef<RNTextProps & TextProps<Theme, EnableShorthand>> &
RefAttributes<{}>
>;

function createText<
Theme extends BaseTheme,
Props extends Record<string, any>,
EnableShorthand extends boolean = true
>(...args: [] | [ComponentType<Props>]) {
>(
...args: [] | [ComponentType<Props>]
): ForwardRefExoticComponent<
PropsWithoutRef<Props & TextProps<Theme, EnableShorthand>> & RefAttributes<{}>
> {
const BaseComponent = args[0] || Text;
return createRestyleComponent<
TextProps<Theme, EnableShorthand> &
Omit<Props, keyof TextProps<Theme, EnableShorthand>>,
Props & TextProps<Theme, EnableShorthand>,
Theme
>(
textRestyleFunctions as RestyleFunctionContainer<
Expand Down

0 comments on commit 64427ba

Please sign in to comment.