fix: type FilterListBox.Item and CommandMenu.Item as CollectionItem - #1284
Merged
Conversation
Both were declared as react-stately's bare `Item`, so `Item` props (`icon`, `rightIcon`, `description`, `hotkeys`, `actions`) were rejected by TypeScript despite working at runtime. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 5574fa4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📦 NPM canary releaseDeployed canary version 0.0.0-canary-e41a2a2. |
Contributor
🧪 Storybook is successfully deployed!
|
Contributor
🏋️ Size limit report
Click here if you want to find out what is changed in this build |
A stale node_modules silently inverts test and type results, which is how a correct source file was "fixed" into a CI failure. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
At runtime
FilterListBox.ItemandCommandMenu.Itemare the very same object asListBox.Item/Menu.Item(CollectionItem), but their declarations pointed at react-stately's bareItem. Consumers therefore got type errors for props that work perfectly at runtime:The gap is invisible inside this repo:
tsconfig.jsonsetspreserveSymlinks: true, which makestypeof Itemfromreact-statelysilently resolve toany(see the existing note intsconfig.json). Consumers compile without that flag, so they see the real — and wrong —ItemProps<T>.Fix
Both components now import
CollectionItem as Itemfromsrc/components/CollectionItem, matching whatComboBox,SearchComboBoxandCommandTextAreaalready do. Purely a typing change —CollectionItemis react-stately'sItemat runtime (Object.assignmutates the target), so no behaviour changes.Also:
FilterListBox.Item = Iteminstead of= ListBox.Item, so the declaration and the assignment refer to the same symbol (identical object either way).mergeProps(customValueProps ?? {}, newCustomValueProps ?? {})— withItemno longerany, TS surfaced thatmergePropsof two optional args produces an intersection includingundefined, which cannot be spread.Audit of the other collection components
Every public component exposing
.Itemwas checked with a type probe compiled withpreserveSymlinks: false(passingdescription+rightIconto.Iteminside a.Section):FilterListBoxItemCollectionItemCommandMenuItemCollectionItemListBox,Menu,SelectCollectionItemPicker,FilterPickertypeof ListBox.ItemComboBox,SearchComboBox,CommandTextAreaCollectionItemalias.Sectionis correct everywhere (plain react-statelySection; the Cube wrappers add only adisplayName).Disclosure.ItemandForm.Itemare unrelated components, not collection items.Verification
tsc --noEmit --preserveSymlinks falseagainst the probe above: 2 errors before (FilterListBox.Item,CommandMenu.Item), 0 after. Probe removed before committing.tsc --noEmit: byte-identical to the pre-change baseline (24 pre-existing errors, no new ones).vitest run: 59 files / 1208 tests passing, 0 failures.oxlint srcandprettier --checkclean.🤖 Generated with Claude Code
Note
Low Risk
Public API is typings-only (runtime unchanged); FilterListBox’s mergeProps tweak is a small defensive typing fix with no intended behavior change.
Overview
FilterListBox.ItemandCommandMenu.Itemnow exposeCollectionItemtypes instead of react-stately’s bareItem, so TypeScript accepts the same extended props (icon,rightIcon,description,hotkeys,actions, etc.) that already work at runtime—aligned withListBox.Item,Menu.Item, andComboBox.In FilterListBox,
FilterListBox.Itemis assigned the sameCollectionItemsymbol used in the module, and custom-valueItemspreads usemergeProps(customValueProps ?? {}, newCustomValueProps ?? {})so optional prop bags type-check afterItemis no longerany.AGENTS.md adds a Before You Start block (
pnpm install && pnpm rebuild esbuild, lockfile version checks) so localtsc/tests aren’t trusted on a stale tree. A patch changeset documents the public typing fix.Reviewed by Cursor Bugbot for commit 5574fa4. Bugbot is set up for automated code reviews on this repo. Configure here.