Skip to content

Commit 9db9a64

Browse files
authored
🤖 Merge PR DefinitelyTyped#74417 Updated @types/pdfkit definition for TableOptions by @ano0002
1 parent 0cc4d1e commit 9db9a64

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

‎types/pdfkit/index.d.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,23 @@ declare namespace PDFKit.Mixins {
466466
/** Column definitions of the table. (default auto) */
467467
columnStyles?:
468468
| number
469-
| Array<number | string>
469+
| Array<number | string | ColumnStyle>
470470
| ColumnStyle
471471
| ((row: number) => number | ColumnStyle | undefined);
472472
/** Row definitions of the table. (default *) */
473-
rowStyles?: number | Array<number | string> | RowStyle | ((row: number) => number | RowStyle | undefined);
473+
rowStyles?:
474+
| number
475+
| Array<number | string | RowStyle>
476+
| RowStyle
477+
| ((row: number) => number | RowStyle | undefined);
474478
/** Defaults to apply to every cell */
475479
defaultStyle?:
476-
& (number | Array<number | string> | CellStyle | ((row: number) => number | CellStyle | undefined))
480+
& (
481+
| number
482+
| Array<number | string>
483+
| CellStyle
484+
| ((row: number) => number | CellStyle | undefined)
485+
)
477486
& { width?: number };
478487
/** Whether to show the debug lines for all the cells (default false) */
479488
debug?: boolean;

‎types/pdfkit/pdfkit-tests.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,28 @@ doc.table({
466466
],
467467
});
468468

469+
// Alternative way to define the same styles as above using arrays
470+
doc.table({
471+
// Set the style for all cells
472+
defaultStyle: { border: 1, borderColor: "gray" },
473+
// Set the style for cells based on their column
474+
columnStyles: [{ border: { left: 2 }, borderColor: { left: "black" } }, {
475+
border: { right: 2 },
476+
borderColor: { right: "black" },
477+
}],
478+
// Set the style for cells based on their row
479+
rowStyles: [{ border: { top: 2 }, borderColor: { top: "black" } }, {
480+
border: { bottom: 2 },
481+
borderColor: { bottom: "black" },
482+
}],
483+
data: [
484+
["Header 1", "Header 2", "Header 3"],
485+
["Sample value 1", "Sample value 2", "Sample value 3"],
486+
["Sample value 1", "Sample value 2", "Sample value 3"],
487+
["Sample value 1", "Sample value 2", "Sample value 3"],
488+
],
489+
});
490+
469491
doc.table({
470492
rowStyles: (i) => {
471493
if (i % 2 === 0) return { backgroundColor: "#ccc" };

0 commit comments

Comments
 (0)