DenseSheet Type annotation #3195

Closed
opened 2024-09-04 14:13:49 +00:00 by yf-yang · 3 comments
Contributor

The type annotation of !data field should be (CellObject | undefined)[][], as blank cell is read as undefined if I got it right.

I am using version 0.20.3

export interface DenseSheet extends Sheet {
    /**
     * Special keys start with '!'
     * Dense-mode worksheets store data in the '!data' key
     */
    [cell: string]: CellObject[][] | SheetKeys | any;

    /**
     * Dense-mode worksheets store data in an array of arrays
     *
     * Cells are accessed with sheet['!data'][R][C] (where R and C are 0-indexed)
     */
    '!data': CellObject[][];
}
The type annotation of !data field should be `(CellObject | undefined)[][]`, as blank cell is read as undefined if I got it right. I am using version 0.20.3 ``` typescript export interface DenseSheet extends Sheet { /** * Special keys start with '!' * Dense-mode worksheets store data in the '!data' key */ [cell: string]: CellObject[][] | SheetKeys | any; /** * Dense-mode worksheets store data in an array of arrays * * Cells are accessed with sheet['!data'][R][C] (where R and C are 0-indexed) */ '!data': CellObject[][]; } ```
Owner

Since the outer array can have holes, the type really should be

type DenseSheetData = ((CellObject | undefined)[]|undefined)[];

For example, consider a CSV with a blank row:

var wsdata = XLSX.read("1,,3\n\n7,,9", {type: "binary", dense: true, cellText: false}).Sheets.Sheet1["!data"];

The result is an array that looks like:

[
  [ {t: "n", v: 1}, /* array hole */, {t: "n", v: 3} ],
  /* array hole */,
  [ {t: "n", v: 7}, /* array hole */, {t: "n", v: 9} ],
]

Based on a simple test on typescriptlang.org, typecheck fails with (object|undefined)[][] but passes with ((object|undefined)[]|undefined)[]

If you agree with the analysis, we'll accept a PR that adds a new DenseSheetData type with the correct annotation.

Since the outer array can have holes, the type really should be ```ts type DenseSheetData = ((CellObject | undefined)[]|undefined)[]; ``` For example, consider a CSV with a blank row: ```js var wsdata = XLSX.read("1,,3\n\n7,,9", {type: "binary", dense: true, cellText: false}).Sheets.Sheet1["!data"]; ``` The result is an array that looks like: ```js [ [ {t: "n", v: 1}, /* array hole */, {t: "n", v: 3} ], /* array hole */, [ {t: "n", v: 7}, /* array hole */, {t: "n", v: 9} ], ] ``` [Based on a simple test on typescriptlang.org](https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAhgJwQLhgChAIwFYFNhQA+ArmACa4BmAlmLmQJQDaAuqzALwxMBQM3MAN5RUAIjCiANDABuqAIwBfaQHoAVPCRwAnjAAWIADa4YaldOFiJ0uTADMimC0l8Y6zQh36jJsy-5MQiIw4lKyqADsym4aiJ66Bsam5kFWYbYAnI7OPCwA3EA), typecheck fails with `(object|undefined)[][]` but passes with `((object|undefined)[]|undefined)[]` If you agree with the analysis, we'll accept a PR that adds a new `DenseSheetData` type with the correct annotation.
Author
Contributor

Sure, I'll make a PR

Sure, I'll make a PR
Owner

Closed by 6912bdb2d4

Closed by 6912bdb2d449525d65244d461e7afe2670d57a75
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3195
No description provided.