Typescript: errors in the xlsx types #2828

Closed
opened 2022-11-16 15:02:37 +00:00 by younes-io · 4 comments

I am using in my Node/Typescript project "xlsx": "file:vendor/xlsx-0.19.0.tgz", and when I start building the project using tsc, I get this:


node_modules/xlsx/types/index.d.ts:567:5 - error TS2411: Property ''!margins'' of type 'MarginInfo | undefined' is not assignable to 'string' index type 'SheetKeys | CellObject[][]'.

567     [cell: string]: CellObject[][] | SheetKeys;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/xlsx/types/index.d.ts:567:5 - error TS2411: Property ''!ref'' of type 'string | undefined' is not assignable to 'string' index type 'SheetKeys | CellObject[][]'.

567     [cell: string]: CellObject[][] | SheetKeys;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/xlsx/types/index.d.ts:567:5 - error TS2411: Property ''!type'' of type 'SheetType | undefined' is not assignable to 'string' index type 'SheetKeys | CellObject[][]'.

567     [cell: string]: CellObject[][] | SheetKeys;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

How do I resolve this? (I also tried with the @types/xlxs but I get the same error)

I am using in my Node/Typescript project `"xlsx": "file:vendor/xlsx-0.19.0.tgz"`, and when I start building the project using `tsc`, I get this: ```shell node_modules/xlsx/types/index.d.ts:567:5 - error TS2411: Property ''!margins'' of type 'MarginInfo | undefined' is not assignable to 'string' index type 'SheetKeys | CellObject[][]'. 567 [cell: string]: CellObject[][] | SheetKeys; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/xlsx/types/index.d.ts:567:5 - error TS2411: Property ''!ref'' of type 'string | undefined' is not assignable to 'string' index type 'SheetKeys | CellObject[][]'. 567 [cell: string]: CellObject[][] | SheetKeys; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/xlsx/types/index.d.ts:567:5 - error TS2411: Property ''!type'' of type 'SheetType | undefined' is not assignable to 'string' index type 'SheetKeys | CellObject[][]'. 567 [cell: string]: CellObject[][] | SheetKeys; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` How do I resolve this? (I also tried with the `@types/xlxs` but I get the same error)
younes-io changed title from Type errors in the xlsx package to Typescript: errors in the xlsx types 2022-11-16 16:38:33 +00:00
Owner

Thanks for the heads up! That is a type error. To unblock immediately, save the attached file to patches/xlsx+0.19.0.patch and run npx patch-package to apply the patch.

The actual patch:

diff --git a/node_modules/xlsx/types/index.d.ts b/node_modules/xlsx/types/index.d.ts
index 12be899..06a25a7 100644
--- a/node_modules/xlsx/types/index.d.ts
+++ b/node_modules/xlsx/types/index.d.ts
@@ -564,7 +564,7 @@ export interface DenseSheet extends Sheet {
      * Special keys start with '!'
      * Dense-mode worksheets store data in the '!data' key
      */
-    [cell: string]: CellObject[][] | SheetKeys;
+    [cell: string]: CellObject[][] | SheetKeys | any;
 
     /**
      * Dense-mode worksheets store data in an array of arrays
Thanks for the heads up! That is a type error. To unblock immediately, save the attached file to `patches/xlsx+0.19.0.patch` and run `npx patch-package` to apply the patch. The actual patch: ```diff diff --git a/node_modules/xlsx/types/index.d.ts b/node_modules/xlsx/types/index.d.ts index 12be899..06a25a7 100644 --- a/node_modules/xlsx/types/index.d.ts +++ b/node_modules/xlsx/types/index.d.ts @@ -564,7 +564,7 @@ export interface DenseSheet extends Sheet { * Special keys start with '!' * Dense-mode worksheets store data in the '!data' key */ - [cell: string]: CellObject[][] | SheetKeys; + [cell: string]: CellObject[][] | SheetKeys | any; /** * Dense-mode worksheets store data in an array of arrays ```
Owner

To test:

mkdir issue2828
cd issue2828
curl -LO https://cdn.sheetjs.com/xlsx-0.19.0/xlsx-0.19.0.tgz
echo "{}" > package.json
npm i --save file:xlsx-0.19.0.tgz
echo "import * as XLSX from 'xlsx'" > test.ts

# this errors
tsc --strict test.ts

# add the patch
mkdir patches
curl -L -o patches/xlsx+0.19.0.patch https://git.sheetjs.com/attachments/19bfa6e8-8e76-49a9-884c-7812954c22ee
npx patch-package

# after patching, no errors
tsc --strict test.ts
To test: ```bash mkdir issue2828 cd issue2828 curl -LO https://cdn.sheetjs.com/xlsx-0.19.0/xlsx-0.19.0.tgz echo "{}" > package.json npm i --save file:xlsx-0.19.0.tgz echo "import * as XLSX from 'xlsx'" > test.ts # this errors tsc --strict test.ts # add the patch mkdir patches curl -L -o patches/xlsx+0.19.0.patch https://git.sheetjs.com/attachments/19bfa6e8-8e76-49a9-884c-7812954c22ee npx patch-package # after patching, no errors tsc --strict test.ts ```
Owner

0.19.1 has the corrected types.

To ensure this does not happen in the future, the Deno tests are run with --check. That should ensure the final test process catches type errors.

0.19.1 has the corrected types. To ensure this does not happen in the future, the Deno tests are run with `--check`. That should ensure the final test process catches type errors.
Author

Thank you

Thank you
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#2828
No description provided.