fix: improve type safety for TreeView and TreeViewItem APIs#505
Merged
Conversation
Made-with: Cursor
bf691d9 to
4bda843
Compare
slimbuck
approved these changes
Feb 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the public TypeScript surface area of TreeView / TreeViewItem by replacing any-typed APIs with explicit, reusable types and correcting JSDoc examples so generated types/docs are more accurate.
Changes:
- Introduces and exports a
ReparentedIteminterface and uses it to type theonReparentcallback and internal reparent bookkeeping. - Types
TreeViewItem.treeViewasTreeView | nullusing a type-only import to avoid runtime circular dependencies. - Tightens
TreeView.filtersetter typing and fixes JSDoc example typing/quotes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/components/index.ts | Re-exports ReparentedItem from the main components barrel. |
| src/components/TreeViewItem/index.ts | Adds `TreeView |
| src/components/TreeView/index.ts | Defines ReparentedItem, types onReparent, improves reparent typing, and types filter setter. |
Comments suppressed due to low confidence (1)
src/components/TreeView/index.ts:1204
filternow acceptsstring | null, but the getter has no explicit return type and currently returnsthis._filter(declared asstring). This can lead to an inconsistent (and less useful) public declaration type in the emitted.d.ts(getter asstring, setter asstring | null). Consider updating the backing field and getter tostring | nullso the accessor pair describes the same public property type.
set filter(value: string | null) {
if (this._filter === value) return;
this._filter = value;
if (value) {
this._applyFilter(value);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Made-with: Cursor
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.
Summary
onReparent: anywith a properly typed callback using a new exportedReparentedIteminterfaceimport type { TreeView }to TreeViewItem and types the publictreeViewgetter/setter asTreeView | nullstring | nulltype to thefiltersetteras TreeViewItemcasts in_getChildIndexand the_onReparentFnreparent branchDetails
ReparentedIteminterface (new, exported):item: TreeViewItem- the reparented itemoldParent: Element- the old parentnewParent?: Element- the new parent (set after reparenting)newChildIndex?: number- the new child indexTreeViewItem.treeView getter/setter now typed as
TreeView | nullinstead ofany. The internal_treeViewfield remainsanysince it calls protected TreeView methods._getChildIndexrefactored to acceptContainerinstead ofTreeViewItem. The old implementation usedindexOf(...) - 1which relied on bothTreeViewandTreeViewItemhaving exactly one internal DOM child before the TreeViewItem children. The new implementation counts onlyTreeViewItemchildren via thedom.uiback-reference, making it robust regardless of how many internal nodes the parent has._onReparentFnbranch similarly updated:fakeDom/getChildrenwidened fromTreeViewItemtoContainer, and the blanketr.newChildIndex--replaced with atreeItemIndexhelper that counts onlyTreeViewItemnodes.Test plan
npm run build)npm test)npm run lint)