From 6905000a9ba62146fb26e541720bbdc7e8526757 Mon Sep 17 00:00:00 2001 From: AlexandrHoroshih Date: Fri, 9 Feb 2024 22:44:21 +0700 Subject: [PATCH] Update types to match desired behavior --- public-types/reflect.d.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/public-types/reflect.d.ts b/public-types/reflect.d.ts index 10d1e38..d96cc1f 100644 --- a/public-types/reflect.d.ts +++ b/public-types/reflect.d.ts @@ -12,6 +12,12 @@ type Hooks = { unmounted?: EventCallable | (() => unknown); }; +/** + * `bind` object type: + * prop key -> store (unwrapped to reactive subscription) or any other value (used as is) + * + * Also handles some edge-cases like enforcing type inference for inlined callbacks + */ type BindFromProps = { [K in keyof Props]?: K extends UnbindableProps ? never @@ -25,6 +31,19 @@ type BindFromProps = { : Store | Props[K]; }; +/** + * Computes final props type based on Props of the view component and Bind object. + * + * Props that are "taken" by Bind object are made **optional** in the final type, + * so it is possible to owerrite them in the component usage anyway + */ +type FinalProps> = Omit< + Props, + keyof Bind +> & { + [K in Extract]?: Props[K]; +}; + // relfect types /** * Operator that creates a component, which props are reactively bound to a store or statically - to any other value. @@ -49,7 +68,7 @@ export function reflect>(config: { * This configuration is passed directly to `useUnit`'s hook second argument. */ useUnitConfig?: UseUnitConfig; -}): FC>; +}): FC>; // Note: FC is used as a return type, because tests on a real Next.js project showed, // that if theoretically better option like (props: ...) => React.ReactNode is used, @@ -83,7 +102,7 @@ export function createReflect>( */ useUnitConfig?: UseUnitConfig; }, -) => FC>; +) => FC>; // list types type PropsifyBind = { @@ -199,7 +218,7 @@ export function variant< */ useUnitConfig?: UseUnitConfig; }, -): FC>; +): FC>; // fromTag types type GetProps = Exclude<