Skip to content

finding(docs): sidebar-nav.mdx's grouped-navigation example leaves navigationItems unannotated, so badgeVariant widens to string and SidebarNav rejects the whole array (TS2322) #6131

Description

@yinlianghui-tw

Measured by the #6120 dev while probing that card's fix (session session_019b5UBNMtTzKbVtZZGvFuxe, on origin/main133e2ea1e, with lucide-react resolution in place from PR #6129). Filed rather than fixed: re-fencing the content/docs/layout blocks is #5867's lane, and #6120 was scoped to the resolution defect only.

The measurement

With PR #6129's third-party resolution in place, four of the five content/docs/layout blocks that were red on lucide-react compile clean. The fifth — content/docs/layout/sidebar-nav.mdx, the "complete example" block whose fence sits at line 191 — is red for its own, unrelated reason:

content/docs/layout/sidebar-nav.mdx:235:7 TS2322: Type '{ label: string; items: (...)[] }[]'
is not assignable to type 'NavItem[] | NavGroup[]'.

The cause

The block writes:

constnavigationItems=[{label: 'Workspace',items: [{title: 'Inbox',href: '/inbox',icon: Mail,badge: 8,badgeVariant: 'destructive'},
...

with no type annotation. So badgeVariant's string literal widens to string, and the declared shape (packages/layout/dist/SidebarNav.d.ts) is a union of literals:

exportinterfaceNavItem{title: string;href: string;badgeVariant?: 'default'|'destructive'|'outline';
...
}exportinterfaceNavGroup{label: string;items: NavItem[]}exportinterfaceSidebarNavProps{items: NavItem[]|NavGroup[]; ... }

string is not assignable to that union, so the NavGroup[] branch fails; TypeScript then reports the other branch of the union, which is why the message reads "missing the following properties from type 'NavItem': title, href" and looks at first like a wrong data shape. The data shape is right. The annotation is missing.

A reader who copies this block verbatim into an annotated position, or who has strict on and assigns it anywhere typed, gets the same error.

Measured fix

Annotating the array — importing the type in the same block, since every block is compiled in isolation — takes it to zero:

import{SidebarNav,typeNavGroup}from'@object-ui/layout';constnavigationItems: NavGroup[]=[

Probed under an EXIT trap with the five layout blocks temporarily re-fenced: Semantic phase: 211 of 211 block(s) judged, 0 failed, gate exit 0. Without the annotation, that same run is 1 failed.

⚠️ Note for whoever takes this: the annotation must resolve, not merely be written. A first probe added : NavGroup[] while the import landed in a different block, producing TS2304: Cannot find name 'NavGroup' — and with the annotation itself erroring, TypeScript stopped checking the literal underneath and the TS2322 disappeared. That is the same false-green shape guide/theming hit (recorded in scripts/check-doc-snippet-types.mjs's ledger): an annotation that errors silently switches off the check it was added to perform.

Scope

Belongs with the content/docs/layout re-fence under #5867 — this block cannot be brought under the gate without it. Filed unassigned.

Refs: #5867 (parent lane) · #6120 / PR #6129 (where this was measured).

Generated by Claude Code

Metadata

Metadata

Labels

documentationImprovements or additions to documentationdomain:devxobjectui devx stream: fix lands on .github/, scripts/ or release pipeline — devx lane cross-repopm:dispatched

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions