How can I remove name not found errors in TypeScript to Apps Script code in VS Code?

32 views Asked by At

I recently transferred my entire code base from the Apps Script Editor to VSCode with Typescript (with clasp). Since I didn't want to just use one large file for everything (especially since some data shouldn't be pushed to GitHub due to security reasons), I instead broke my code into many files, with 1 main file with all the functions and the rest of the files serving as data holders.

The IDE immediately found errors because TypeScript can't find the names (ts(2304)) in the main file since these were declared in other files. I tried exporting the variables of the other files for a few hours, but then found out that the project was failing to compile the whole time because Apps Script doesn't support the export/import scheme. It's only a problem within the IDE; when pushing the code base to Apps Script it runs fine without errors (I think because it's putting everything in one huge file then running it as that).

// for example

function calendarReminderSystem() {
    // get calendar
    let calendar: Calendar = CalendarApp.getOwnedCalendarById(CALENDAR_ID)
    console.log(`Calendar: ${calendar.getName()}`)

    // get date
    let now = new Date()
    now.setHours(0, 0, 0, 0)
    let end = new Date(now.getTime() + 7 * DAY)
    end.setHours(23, 59, 59, 999)
    console.log(`now: ${now.getTime()}, 7 from now: ${end.getTime()}`)

    // email addresses
    const sharedUsers = cleanEmails(EMAIL_ADDRESSES)
    console.log(`Users: ${sharedUsers}`)

    // ...
}

Here, CALENDAR_ID, DAY, and EMAIL_ADDRESSES are all constants included in other files, but since I haven't done any import/export VSC throws red lines at me, but the thing still works when pushed to Apps Script.

Just to note if needed: I don't have a tsconfig.json in my folder, I let Apps Script handle the configurations for me because I am a newbie who is extremely new to TypeScript after being tired of dealing with JavaScript shenanigans.

Is there a way to remove these red lines without using import/export? Is there also a way for VSC to throw red lines when the variables are indeed nowhere to be found in the whole code base?

0

There are 0 answers