fix(tree,treeselect,organizationchart): enable generic type inference for value/options and slots#8497
Open
YevheniiKotyrlo wants to merge 1 commit intoprimefaces:masterfrom
Open
Conversation
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.
Defect Fixes
Fixes #8496
Tree, TreeSelect, and OrganizationChart use
TreeNode/OrganizationChartNodefor their data props and all slot scoped data. Both interfaces have a[key: string]: anyindex signature. Developers who extend these interfaces with custom properties get no type safety — custom properties resolve toanyvia the index signature instead of their declared types.Same root cause as #8442 —
DefineComponent's no-arg constructor prevents generic inference. Same fix pattern as #8444 (DataTable/DatePicker).Related: #7426, #6041
Reproducer: StackBlitz —
bun run type-check(0 errors, typo undetected) →bun run patch && bun run type-check(TS2339 catches it)Problem
After this fix, TypeScript infers
T = MyTreeNodefrom the:valuebinding and flows it to all slots:Changes
Tree:
TreeProps<T extends TreeNode = TreeNode>—value: T[],filterBycallback(node: T) => stringTreeSlots<T extends TreeNode = TreeNode>— all 5+ slots withnode: T, catch-all[key: string]: (node: T) => VNode[]DefineComponentTreeSelect:
TreeSelectProps<T extends TreeNode = TreeNode>—options: T[],modelValue: T | any,filterBycallback(node: T) => stringTreeSelectSlots<T extends TreeNode = TreeNode>—node: Tin option/toggle slots (removes incorrect| any),options: T[]in header/footer& TreeSelectMethodsOrganizationChart:
OrganizationChartProps<T extends OrganizationChartNode = OrganizationChartNode>—value: TOrganizationChartSlots<T extends OrganizationChartNode = OrganizationChartNode>—node: Tin default slot, catch-all[key: string]: (node: T) => VNode[]DefineComponentWhat gets typed
#defaultnodeTreeNodeT#nodeicon/#nodetoggleiconnodeTreeNodeT[key: string]nodeanyT#optionnodeTreeNode | anyT#header/#footeroptionsTreeNode[]T[]#defaultnodeanyT[key: string]nodeanyTScope / Impact
Tdefaults toTreeNode/OrganizationChartNodeVerification
pnpm run format:checkpnpm run lintpnpm run test:unitpnpm run build:packagesNODE_ENV=syntax), 0 newSeries
This is part of a series bringing generic type inference to all PrimeVue data components:
ofprop)After this series, every PrimeVue component with a collection prop will infer
Tfrom the binding and flow it to slots — giving developers full IDE autocomplete and compile-time type safety in templates.