I tested using the following code and had no issues:
The only items that I changed were renaming "Sheet 1" to "Sheet1"
function main(workbook: ExcelScript.Workbook) {
let currentWorksheet = workbook.getWorksheet("Sheet1");
// Get the range containing all the cells with data or formatting.
let usedRange = currentWorksheet.getUsedRange();
// Log the range's address to the console.
console.log(usedRange.getAddress());
currentWorksheet.getAutoFilter().clearCriteria;
currentWorksheet.getAutoFilter().remove;
//Add table
let table1 = currentWorksheet.addTable(usedRange, true);
}
Image of Autofiltered Table that I used:

Image after running Script above:

Below is the console log output:
Sheet1!A1:C6