diff --git a/public-types/reflect.d.ts b/public-types/reflect.d.ts index 360b1eb..10d1e38 100644 --- a/public-types/reflect.d.ts +++ b/public-types/reflect.d.ts @@ -20,6 +20,8 @@ type BindFromProps = { | ((...args: Parameters) => ReturnType) // Edge-case: allow to pass an event listener without any parameters (e.g. onClick: () => ...) | (() => ReturnType) + // Edge-case: allow to pass an Store, which contains a function + | Store : Store | Props[K]; }; diff --git a/type-tests/types-reflect.tsx b/type-tests/types-reflect.tsx index 7a6b15f..232df8b 100644 --- a/type-tests/types-reflect.tsx +++ b/type-tests/types-reflect.tsx @@ -182,6 +182,50 @@ import { expectType } from 'tsd'; expectType(ReflectedInput); } +// should allow store with a function as a callback value +{ + const Input: React.FC<{ + value: string; + onChange: (newValue: string) => void; + }> = () => null; + const $changed = createStore<(newValue: string) => void>(() => {}); + + const ReflectedInput = reflect({ + view: Input, + bind: { + value: 'plain string', + onChange: $changed, + }, + }); + + expectType(ReflectedInput); +} + +function localize(value: T): { lol: boolean }; +function localize(value: T): { kek: boolean }; +function localize(value: string): unknown { + return value; +} + +// should allow store with generics +{ + const Input: React.FC<{ + value: string; + onChange: typeof localize; + }> = () => null; + const $changed = createStore(localize); + + const ReflectedInput = reflect({ + view: Input, + bind: { + value: 'plain string', + onChange: $changed, + }, + }); + + expectType(ReflectedInput); +} + // should support useUnit configuration { const Input: React.FC<{