TypeScript: colReorder: true is rejected by Options in DataTables 3.x
TypeScript: colReorder: true is rejected by Options in DataTables 3.x
Link to test case: https://stackblitz.com/edit/vitejs-vite-yyaf782f?file=src%2Fmain.ts
Hi,
I'm using DataTables 3.0.2 with ColReorder 3.0.1 and TypeScript 5.9.3.
The documented initialization syntax allows colReorder to be a boolean:
new DataTable('#example', {
colReorder: true
});
However, when the config object is typed as Options, TypeScript rejects true:
import DataTable from 'datatables.net-dt';
import 'datatables.net-colreorder-dt';import type { Options } from 'datatables.net-dt';
const config: Options = {
colReorder: true
};
The Typescript error is:
Type boolean has no properties in common with type '...'
My understanding is that the initialization option should accept:
boolean | ConfigColReorder
but through the current Options type it seems to resolve to only ConfigColReorder.
Expected behavior: colReorder: true should be accepted by TypeScript, since it is a documented and supported initialization value.
Actual behavior: TypeScript reports that boolean is not assignable to ConfigColReorder.
This question has an accepted answers - jump to answer
Answers
Hi,
Many thanks for letting me know about this error. I had a mistake in my naming of the property which is being extended for the configuration options (used
Configrather thanOptions).I've committed a fix and am about to go through the other extensions which almost certainly have the same issue.
The reason the object form works is that
Defaultsis extended as well, and that is the basis forOptions.I'll issue patch releases with the fixes soon.
Allan