UNPKG

@donverduyn/react-runtime

Version:
60 lines (59 loc) 4.03 kB
import * as React from 'react'; import type { Simplify, Merge, IsNever, IsLiteral, IsUnknown, IsEmptyObject } from 'type-fest'; import type { PROPS_PROP, ExtractStaticProps, ProviderFn, IdProp, ExtensibleProps, ResultProps, ERROR_PROP, UpstreamProviderFn, RuntimeContext } from '@/types'; import { type ExtractMeta } from '@/utils/react'; import type { PropService } from 'utils/effect'; export declare function WithUpstream<CProps, // component props static TProps extends ExtensibleProps<CProps>, // local provider props (inferred) PProps, // providerProps cumulative PErrors>(fn: UpstreamProviderFn<Simplify<PProps & Partial<CProps>>, TProps>): (Component: ({ [PROPS_PROP]: PProps; } & React.FC<CProps>) | ({ [ERROR_PROP]: PErrors; } & React.FC<CProps>) | React.FC<CProps>) => [ IsUnknown<PErrors>, IsLiteral<keyof TProps> & IsEmptyObject<TProps> ] extends [true, 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 WithUpstream<CProps, TProps extends Partial<IdProp & Record<string, unknown>> | void, PProps, PErrors>(fnVoid: UpstreamProviderFn<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']; }; /** * @deprecated In the upcoming 2.0 release, we will remove support for runtime modules as argument. Instead, use the inject API from the function arguments. */ export declare function WithUpstream<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>, ..._deprecated: never[]): (Component: ({ [PROPS_PROP]: PProps; } & React.FC<CProps>) | ({ [ERROR_PROP]: PErrors; } & React.FC<CProps>) | React.FC<CProps>) => [ IsUnknown<PErrors>, IsLiteral<keyof TProps> & IsEmptyObject<TProps> ] extends [true, 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']; }; /** * @deprecated In the upcoming 2.0 release, we will remove support for runtime modules as argument. Instead, use the inject API from the function arguments. */ export declare function WithUpstream<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)>, ..._deprecated: never[]): (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 {};