You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up to PR #102 (mapProps feature). Addresses all review points:
#1 — Runtime tests added for variant, list, createReflect (no-ssr + ssr).
Previously only reflect had mapProps coverage.
#2 — Unknown mapProps keys now error at the key site itself, not on fn's
return. MapPropsFromSources resolves unknown-key entries to never,
producing a TS2322 at the key line. Replaces the old
'K extends keyof Props ? Props[K] : never' fn-return approach that
had a silent-failure path (never-returning fn compiled cleanly).
#3 — Documented the Store<any> variable-source widening limitation.
Type tests (3a positive, 3b widening) pin the current behavior.
#4 — fn is skipped when its key is overridden by an external prop.
'if (key in props) continue' in src/core/reflect.ts. Spy assertions
in reflect and createReflect tests verify fn is not called.
B1 — bind + mapProps key collision is now a type error. MapPropsFromSources
takes Bind as a type parameter; a key in both bind and mapProps
resolves to never. Runtime skip ('if (key in storeProps) continue')
is a defense-in-depth for JS/type-bypass scenarios (covers stores;
events/data/functions are covered by the type fix).
B2 — mapItem + mapProps key collision in list is a type error. MapItem's
mapped type now omits keyof Sources alongside keyof Bind. Partial:
bypassable with explicit item-parameter annotation (known TS
limitation with mapped-type extends constraints), documented in the
type-test comment.
All four operators (reflect, createReflect, list, variant) are covered
by the type fixes and runtime tests.
Docs updated in docs/pages/docs/reflect.mdx:
- mapProps keys must be props of the view; unknown keys error at the key
- a key must not appear in both bind and mapProps
- in list, a key must not appear in both mapItem and mapProps
- source should be an inline literal for best inference
- fn is not invoked when its key is overridden
80 runtime tests + type tests pass.
Copy file name to clipboardExpand all lines: docs/pages/docs/reflect.mdx
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,8 @@ Each entry is `{ source, fn }`:
95
95
- an **array** of stores — `value` is the resolved tuple (`[Store<A>, Store<B>]` → `[A, B]`).
96
96
-`fn` — `(value, props) => derivedProp`, where `value` is the resolved `source` value (its type is inferred — no annotation needed) and `props` are the component's own props.
97
97
98
+
> Each key in `mapProps` must be a prop of the `view` — a typo'd or unknown key is a type error at the key itself. A key must not appear in both `bind` and `mapProps` — this is a type error. For best type inference, pass `source` as an inline literal; a variable typed as `Store<any>` will widen `fn`'s `value` argument to `any`.
99
+
98
100
```tsx
99
101
import { reflect } from'@effector/reflect';
100
102
import { createStore } from'effector';
@@ -143,9 +145,10 @@ const Hello = reflect({
143
145
144
146
The component re-renders only when the `source` changes. A prop computed via `mapProps`
145
147
is made **optional** in the resulting component's type and can still be overridden explicitly at
146
-
the usage site (an explicitly passed prop wins over the derived value).
148
+
the usage site (an explicitly passed prop wins over the derived value — in that case `fn` is
149
+
not invoked for the overridden key).
147
150
148
-
> Note: like `bind`, the `mapProps` field is supported by all Reflect operators — `reflect`, `createReflect`, `variant` and `list`.
151
+
> Note: like `bind`, the `mapProps` field is supported by all Reflect operators — `reflect`, `createReflect`, `variant` and `list`. In `list`, a key must not appear in both `mapItem` and `mapProps` — `mapItem` automatically omits keys that are derived via `mapProps`.
0 commit comments