Skip to content
This repository was archived by the owner on Jun 28, 2026. It is now read-only.

fix(datatable,datepicker,paginator): enable generic type inference for T, F, V, and PS - #8444

Open
YevheniiKotyrlo wants to merge 3 commits into
primefaces:masterfrom
YevheniiKotyrlo:fix/generic-type-inference
Open

fix(datatable,datepicker,paginator): enable generic type inference for T, F, V, and PS#8444
YevheniiKotyrlo wants to merge 3 commits into
primefaces:masterfrom
YevheniiKotyrlo:fix/generic-type-inference

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Feb 17, 2026

Copy link
Copy Markdown

Summary

Enable TypeScript to infer generic type parameters from template bindings for DataTable, DatePicker, and Paginator. This completes the work started in #7427 by switching component declarations from DefineComponent (no-arg constructor) to generic constructors that accept props.

Generic parameters added

Component Generic Inferred from Enables
DataTable T (row data) :value Typed #groupheader/#groupfooter/#expansion slots, rowClass/rowStyle callbacks, sortField autocomplete
DataTable F (filters) v-model:filters Typed update:filters emit — eliminates 5 strictTemplates errors
DataTable PS (page size) :rows-per-page-options rows prop, update:rows emit, and page event rows field narrowed to configured values
DatePicker V (model value) v-model Typed update:modelValue emit — eliminates 1 strictTemplates error
Paginator PS (page size) :rows-per-page-options Same narrowing flows through PageState, slots, and emits

All generics default to their original types (T = any, F = DataTableFilterMeta, PS = number, V = Date | ...), so this is fully backward compatible.

How it works

PrimeVue's DefineComponent uses a no-arg constructor (new ()), which prevents TypeScript from inferring generics from template bindings. vue-tsc already generates new DataTable({ value: data, ... }) — but with the no-arg constructor, the props are ignored for inference.

The fix replaces DefineComponent<Props, Slots, Emits> with an explicit generic constructor:

declare const DataTable: {
    new <T = any, F extends DataTableFilterMeta = DataTableFilterMeta, PS extends number = number>(
        props: Omit<DataTableProps<T, PS>, 'filters'> & { filters?: F }
    ): {
        $props: Omit<DataTableProps<T, PS>, 'filters'> & { filters?: F } & VNodeProps & AllowedComponentProps & ComponentCustomProps;
        $slots: DataTableSlots<T, PS>;
        $emit: EmitFn<DataTableEmitsOptions<T, F, PS>>;
    } & DataTableMethods;
};

PS page-size generic flow

rowsPerPageOptions now accepts readonly PS[]. When consumers pass a const tuple like [5, 10, 20, 50] as const, TypeScript infers PS = 5 | 10 | 20 | 50 and narrows:

  • rows prop to PS (only configured page sizes)
  • update:rows emit to PS
  • DataTablePageEvent.rows to PS
  • rowChangeCallback to (value: PS) => void
  • PageState.rows to PS

Files changed

  • packages/primevue/src/datatable/DataTable.d.ts — T, F, PS generics on DataTable
  • packages/primevue/src/datepicker/DatePicker.d.ts — V generic on DatePicker
  • packages/primevue/src/paginator/Paginator.d.ts — PS generic on Paginator

Related issues

Test plan

  • prettier --check passes
  • eslint . passes
  • Type check: zero errors in changed files
  • pnpm run build:lib succeeds, dist output includes all generics
  • Unit tests: 74/78 pass (4 failures pre-existing, identical without changes)
  • Backward compatible: all generics default to original types

Add a third generic parameter PS (page size) to DataTable and Paginator
type definitions, enabling TypeScript to narrow rows/rowsPerPageOptions
to specific configured values (e.g., 5 | 10 | 20 | 50) instead of
plain number.

The generic flows end-to-end: rowsPerPageOptions accepts readonly PS[],
rows prop and events emit PS, and rowChangeCallback receives PS.
Defaults to number for full backward compatibility.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataTable v-model:filters and DatePicker v-model lose type specificity (DefineComponent no-arg constructor)

1 participant