fix(datatable,datepicker): enable generic type inference for T, F, and V#8444
Open
YevheniiKotyrlo wants to merge 2 commits intoprimefaces:masterfrom
Open
fix(datatable,datepicker): enable generic type inference for T, F, and V#8444YevheniiKotyrlo wants to merge 2 commits intoprimefaces:masterfrom
YevheniiKotyrlo wants to merge 2 commits intoprimefaces:masterfrom
Conversation
59a73a0 to
20900af
Compare
This was referenced Mar 11, 2026
Open
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 #8442
DataTable and DatePicker lose type specificity through
DefineComponent's no-arg constructor. This completes #7427, which madeDataTableProps<T>generic but left the component declaration usingDefineComponentwithnew ()— soTis never inferred from template bindings. Users are still reporting this in #7426.Related: #7426, #6041, #7838
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:valueandFfromv-model:filters:The template code is identical — only the type inference changes.
v-model:filtersalso emits the consumer's specific filter type instead of the widestDataTableFilterMetaunion.Root cause
PrimeVue's
DefineComponentusesnew ()(no-arg constructor). vue-tsc generatesnew Component({...props...})in template codegen and infersKfrom the instance. But with a no-arg constructor,InstanceType<T>erases generic parameters to defaults.When the constructor accepts props (
new <T, F>(props: P)), TypeScript infers generics from the actual prop values — and vue-tsc's existing codegen makes this work automatically.Scope / Impact
@ts-ignorein vue-tsc codegenThis aligns with the approach used in #8287 (generic DynamicDialogCloseOptions) and builds on the foundation from #7427.
Changes
DataTable —
T(row data) +F(filters):Tto constructor — inferred from:valuebinding, flows to$slotsand$emitF extends DataTableFilterMetato constructor — inferred fromv-model:filterssortFieldfromkeyof TtoHintedString<keyof T & string>— whenTis inferred (notany),keyof Tbecomes a strict union that breaks consumers passing plain strings.HintedStringaccepts any string but provides autocomplete for known keys (the same pattern already used foralignFrozen,selectionMode, etc.)NoInfer<T>on secondary props (selection,expandedRows) preventsTfrom being inferred from the wrong source — only from:valueT = any)Tinferred from:value)sortFieldkeyof Tkeys#groupheader/#groupfooter/#expansionslotdataanyTrowClass/rowStylecallback paramanyTDatePicker —
V(model value):Vto constructor — inferred fromv-modelbinding'update:modelValue'and'value-change'emit the specificVtype instead of the widest unionHow it works
vue-tsc already generates
new DataTable({ value: orders.value, filters: filters.value })in template codegen. With the generic constructor, TypeScript infersTfromvalueandFfromfilters, and the emit callbacks receive the same types — makingv-model:filtersand slot scoped data fully type-safe.Verification
vue-tsc --noEmitwithstrictTemplatessortFieldwithHintedString<keyof T & string>NoInfer<T>onselection/expandedRowsTonly inferred from:value@ts-ignorein vue-tsc codegen handles itSeries
This is the first PR in 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.