Skip to content

Commit 6b978f1

Browse files
committed
docs(core): fix ComponentRegistry singleton example in README
packages/core/README.md's Component Registry snippet taught `new ComponentRegistry()`, but ComponentRegistry is an exported singleton instance, not a class -- packages/core/dist/registry/Registry.d.ts declares `export declare const ComponentRegistry: Registry<any>`. The #5138 doc-snippet type gate measures this as TS2351: This expression is not constructable. README ships to npm inside the package's `files`, so a reader who copied the snippet got a compile error. Drops the `new`, calls ComponentRegistry.register/get directly on the singleton, and adds one line stating it is the process-level shared instance SchemaRenderer resolves every `type` against -- the same wording packages/components/README.md was given in #5160, kept consistent across both READMEs. Updates the UNGATED_DOCS ledger entry for packages/core/README.md in scripts/check-doc-snippet-types.mjs: TS2351x1 is dropped from the reason text now that the diagnostic is gone (measured before/after against the built dist/*.d.ts). The entry is not deleted -- the document's remaining TS2339x2 pair is a separate, pre-existing defect out of scope here, tracked as #5257. Fixes #5258 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RV6yuVCxymHYE16PL9vQkE
1 parent bc2922a commit 6b978f1

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
Fix `packages/core/README.md`'s Component Registry example, which taught
6+
`new ComponentRegistry()` against an exported singleton **instance**, not a
7+
class — the built `packages/core/dist/registry/Registry.d.ts` declares
8+
`export declare const ComponentRegistry: Registry<any>`, so the snippet did
9+
not compile (`TS2351: This expression is not constructable`, measured by the
10+
objectui#5138 doc-snippet type gate). A reader who copied it got a compile
11+
error; if `new ComponentRegistry()` had compiled it would have produced a
12+
second, empty registry nothing renders from, the more expensive half of the
13+
mistake.
14+
15+
The snippet now calls `ComponentRegistry.register(...)` /
16+
`ComponentRegistry.get(...)` directly on the singleton, with one line stating
17+
it is the process-level shared instance `SchemaRenderer` resolves every
18+
`type` against — the same wording `packages/components/README.md` was given
19+
in objectui#5160, kept consistent across both READMEs. Readers who want their
20+
own isolated registry still have `Registry` itself, separately exported as a
21+
real class.
22+
23+
`scripts/check-doc-snippet-types.mjs`'s `UNGATED_DOCS` entry for
24+
`packages/core/README.md` is updated to match: `TS2351x1` is dropped from its
25+
reason text now that the diagnostic is gone. The entry is not deleted — the
26+
document's remaining `TS2339x2` pair (a different, pre-existing defect) is
27+
out of scope for this change; it's tracked as objectui#5257.

‎packages/core/README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ const mySchema: PageNodeSchema = {
4646
```typescript
4747
import { ComponentRegistry } from '@object-ui/core'
4848

49-
const registry = new ComponentRegistry()
50-
registry.register('button', buttonMetadata)
51-
const metadata = registry.get('button')
49+
ComponentRegistry.register('button', buttonMetadata)
50+
const metadata = ComponentRegistry.get('button')
5251
```
5352

53+
`ComponentRegistry` is a process-level singleton exported by `@object-ui/core`;
54+
`SchemaRenderer` resolves every `type` against it, so a component registered
55+
here is renderable from schema anywhere in the app.
56+
5457
### Data Scope
5558

5659
`DataScopeManager` owns the named scopes a component tree reads from, and

‎scripts/check-doc-snippet-types.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const UNGATED_DOCS = {
246246
'packages/components/README.md':
247247
'1 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines',
248248
'packages/core/README.md':
249-
'5 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2339x2 TS2351x1 — candidate real defects, un-triaged',
249+
'5 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2339x2 — candidate real defects, un-triaged',
250250
'packages/data-objectstack/README.md':
251251
'10 parse diagnostic(s) — blocks fenced `ts` that are bare object literals or elided bodies; 41 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines',
252252
'packages/fields/README.md':

0 commit comments

Comments
 (0)