Skip to content

Commit f7d1c76

Browse files
sergeyshmakovclaude
andcommitted
docs: fix root type in types.mdx wildcard-vs-literal example
The example declared the root as Record<string, number> but the path was three levels deep and the sample data was nested two more levels — { a: { "*": { b: 1 }, x: { b: 2 } } }. Type-checked but lied about the leaf type. - Introduce explicit type aliases (Data, Bag) so the root shape is visible and matches the path / data. - unsafePath now takes <Bag, number> so .get() returns number | undefined rather than unknown. - Switch the template example to the lambda form path((d: Data) => d.items) since path<T>() returns a Path<T,T> with no proxy access; the old path<T>().items.each() didn't actually compile. - Drop the unused DEEP_WILDCARD import. Verified by spinning up a tmp spec that runs both snippets and passes under --typecheck. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 99b453e commit f7d1c76

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

docs/src/content/docs/reference/types.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ const segments: Segment[] = ["profile", "tags", 0];
107107
Templates created by `.each()` and `.deep()` insert wildcard sentinels into their segment list. The sentinels are unique `Symbol` values (not the strings `"*"` / `"**"`), so legitimate object keys named `"*"` or `"**"` are preserved as literal segments and never reinterpreted as wildcards.
108108

109109
```ts
110-
import { path, WILDCARD, DEEP_WILDCARD } from "data-path";
110+
import { path, unsafePath, WILDCARD } from "data-path";
111111

112-
const tmpl = path<{ items: { id: string }[] }>().items.each();
112+
type Data = { items: { id: string }[] };
113+
const tmpl = path((d: Data) => d.items).each();
113114
tmpl.segments; // ["items", WILDCARD] — symbol, not the string "*"
114115
tmpl.$; // "items.*" — renders as "*" in dot-notation
115116

116-
const literal = unsafePath<Record<string, number>>("a.*.b");
117+
type Bag = { a: Record<string, { b: number }> };
118+
const literal = unsafePath<Bag, number>("a.*.b");
117119
literal.segments; // ["a", "*", "b"] — pure strings; "*" is a literal key
118120
literal.get({ a: { "*": { b: 1 }, x: { b: 2 } } }); // 1
119121
```

0 commit comments

Comments
 (0)