Closed
Description
🐛 Bug Report
This bug is typescript-only. The getWorksheet
method specifies Worksheet
as its return type, but when passing a non-existing sheet name as parameter, it returns in reality undefined
.
Lib version: 4.3.0
Why is it an issue
If the undefined
possibility isn't specified, then it's easy for developers to forget to account for this possibility when parsing a file coming from a user.
Steps To Reproduce
const wb = new ExcelJS.Workbook();
const ws = wb.getWorksheet('nonExisting');
// type of ws : Worksheet
// actual value of ws : undefined
const row = ws.getRow(1) // throws
The expected behaviour:
the return type should be Worksheet | undefined
Possible solution
// modify the return type in index.d.ts
// line 1746
getWorksheet(indexOrName: number | string): Worksheet | undefined;
Metadata
Metadata
Assignees
Labels
No labels