UNPKG

@donverduyn/react-runtime

Version:
30 lines (29 loc) 2.1 kB
import * as React from 'react'; import type { Simplify, Merge, IsNever, IsUnknown, IsLiteral } from 'type-fest'; import type { PROPS_PROP, ExtractStaticProps, ProviderFn, IdProp, ExtensibleProps, ResultProps, ERROR_PROP, RuntimeContext } from '@/types'; import { type ExtractMeta } from '@/utils/react'; import type { PropService } from 'utils/effect'; export declare function WithRuntime<R, CProps, // component props static TProps extends ExtensibleProps<CProps>, // local provider props (inferred) PProps, // providerProps cumulative PErrors>(module: RuntimeContext<R, never, PropService>, fn?: ProviderFn<R, PProps & Partial<CProps>, TProps>): (Component: ({ [PROPS_PROP]: PProps; } & React.FC<CProps>) | ({ [ERROR_PROP]: PErrors; } & 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']; }; export declare function WithRuntime<R, CProps, TProps extends Partial<IdProp & Record<string, unknown>> | void, PProps, PErrors>(module: RuntimeContext<R, never, PropService>, fnVoid?: ProviderFn<R, PProps & Partial<CProps>, TProps & (TProps extends Record<string, unknown> ? Partial<IdProp & CProps> : void)>): (Component: ({ [PROPS_PROP]: PProps; } & React.FC<CProps>) | ({ [ERROR_PROP]: PErrors; } & React.FC<CProps>) | React.FC<CProps>) => IsUnknown<PErrors> extends true ? React.FC<Simplify<Partial<IdProp> & CProps>> & StaticProperties<React.FC<Simplify<CProps>>, PProps, PErrors> : 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 {};