diff --git a/types/pdfkit/index.d.ts b/types/pdfkit/index.d.ts index 21498be7117a89..baf6d1016e3a2c 100644 --- a/types/pdfkit/index.d.ts +++ b/types/pdfkit/index.d.ts @@ -466,14 +466,23 @@ declare namespace PDFKit.Mixins { /** Column definitions of the table. (default auto) */ columnStyles?: | number - | Array + | Array | ColumnStyle | ((row: number) => number | ColumnStyle | undefined); /** Row definitions of the table. (default *) */ - rowStyles?: number | Array | RowStyle | ((row: number) => number | RowStyle | undefined); + rowStyles?: + | number + | Array + | RowStyle + | ((row: number) => number | RowStyle | undefined); /** Defaults to apply to every cell */ defaultStyle?: - & (number | Array | CellStyle | ((row: number) => number | CellStyle | undefined)) + & ( + | number + | Array + | CellStyle + | ((row: number) => number | CellStyle | undefined) + ) & { width?: number }; /** Whether to show the debug lines for all the cells (default false) */ debug?: boolean; diff --git a/types/pdfkit/pdfkit-tests.ts b/types/pdfkit/pdfkit-tests.ts index b6147e8993cc72..a1714dfbc70f5c 100644 --- a/types/pdfkit/pdfkit-tests.ts +++ b/types/pdfkit/pdfkit-tests.ts @@ -466,6 +466,28 @@ doc.table({ ], }); +// Alternative way to define the same styles as above using arrays +doc.table({ + // Set the style for all cells + defaultStyle: { border: 1, borderColor: "gray" }, + // Set the style for cells based on their column + columnStyles: [{ border: { left: 2 }, borderColor: { left: "black" } }, { + border: { right: 2 }, + borderColor: { right: "black" }, + }], + // Set the style for cells based on their row + rowStyles: [{ border: { top: 2 }, borderColor: { top: "black" } }, { + border: { bottom: 2 }, + borderColor: { bottom: "black" }, + }], + data: [ + ["Header 1", "Header 2", "Header 3"], + ["Sample value 1", "Sample value 2", "Sample value 3"], + ["Sample value 1", "Sample value 2", "Sample value 3"], + ["Sample value 1", "Sample value 2", "Sample value 3"], + ], +}); + doc.table({ rowStyles: (i) => { if (i % 2 === 0) return { backgroundColor: "#ccc" };