fix(autocomplete,cascadeselect,dataview): enable generic type inference for options and slots#8489
Open
YevheniiKotyrlo wants to merge 2 commits intoprimefaces:masterfrom
Conversation
This was referenced Mar 11, 2026
Open
…ce for options, slots, and events
a89287e to
52bab93
Compare
…ference Same approach as Select/MultiSelect/Listbox (PR primefaces#8484): when optionGroupChildren is set, the #option slot receives child items, not the group objects. A single T generic types the slot incorrectly. AutoComplete now uses <T, C> with three constructor overloads: - Function accessor: C inferred from optionGroupChildren return type - String accessor: C falls back to any - No groups: C = T (backward compatible) CascadeSelect and DataView are not affected (CascadeSelect renders all levels in a single #option slot; DataView has no optionGroup).
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 #8486
AutoComplete, CascadeSelect, and DataView use
anyfor their data arrays, slot scoped data, and event payloads. Developers get no type safety when working with suggestion/option slots or option-select events.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
Tfrom the data binding and flows it to all slots and events:Event handlers also benefit —
option-selectandoption-unselectnow carry the inferred type:Changes
AutoComplete and CascadeSelect:
[Component]Props<T = any>—suggestions/options: T[], callback params(data: T) => ...[Component]Slots<T = any>—option: T,suggestions/options: T[]in header/footer slotsnew <T = any>(props)with$slots,$emitboth wired toTmodelValuestaysany— whenoptionValueis set, the value is the extracted scalar, not the option objectAutoComplete events (additional):
AutoCompleteOptionSelectEvent<T = any>—value: Tinstead ofvalue: anyAutoCompleteOptionUnselectEvent<T = any>— extends generic select eventAutoCompleteEmitsOptions<T = any>— select/unselect emits use generic event typesAutoCompleteEmits<T = any>— propagatesTthroughEmitFnDataView:
DataViewProps<T>already exists withvalue: T[]— props were already generic from a previous PRDataViewSlots<T = unknown>— wires existingTtolistandgridslotitems: T[]DefineComponent— completing the generic plumbing that was left half-doneWhat gets typed
#optionslotoptionanyT#header/#footerslotsuggestionsany[]T[]optionLabelcallback paramanyToption-selecteventvalueanyToption-unselecteventvalueanyT#optionslotoptionanyT#header/#footerslotoptionsany[]T[]optionLabel/optionValue/optionDisabledcallback paramanyT#list/#gridslotitemsanyT[]Scope / Impact
Tdefaults toanyVerification
pnpm run format:checkpnpm run lintpnpm run test:unitpnpm run build:packagesSeries
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 and events — giving developers full IDE autocomplete and compile-time type safety in templates.