UNPKG

@donverduyn/react-runtime

Version:
17 lines (16 loc) 1.17 kB
import * as React from 'react'; import type { Simplify, Merge, IsLiteral, IsUnknown, IsNever } from 'type-fest'; import { type PROPS_PROP, type ExtractStaticProps, type PropsFn, type ExtensibleProps, type ERROR_PROP, type ResultProps } from '@/types'; import { type ExtractMeta } from '@/utils/react'; export declare function WithProps<CProps, TProps extends ExtensibleProps<CProps>, PProps, PErrors>(fn: PropsFn<PProps & Partial<CProps>, TProps>): (Component: ({ [PROPS_PROP]: PProps; } & React.FC<CProps>) | React.FC<CProps>) => IsUnknown<PErrors> extends true ? React.FC<Simplify<ResultProps<CProps, TProps>>> & StaticProperties<React.FC<Simplify<CProps>>, Readonly<Merge<PProps, IsLiteral<keyof TProps> extends true ? TProps : {}>>, PErrors> : // constraint widening on error with overlap React.FC<Simplify<CProps>> & { _error: ['Type mismatch on provided props']; }; type StaticProperties<C, TProps, TErrors = unknown> = TErrors extends [string] ? Merge<ExtractMeta<C>, { [ERROR_PROP]: TErrors; }> : Merge<ExtractMeta<C>, { [PROPS_PROP]: IsNever<TProps> extends false ? Merge<ExtractStaticProps<C>, TProps> : ExtractStaticProps<C>; }>; export {};