Takuya HARA
Takuya HARA

Reputation: 657

How to tell TS Server like all JS codes are in a single file?

I use clasp and VS Code to develop app which runs as Google Apps Script. In Google Apps Script every codes work as if they are written in a single file so the following results error.

a.js

const foo = "foo";

b.js

const foo = "bar";

It is virtually like:

const foo = "foo";
const foo = "bar";

When coding on VS Code I get no error from TS Server but I want it. In other word I want TS Server to treat all codes are in a single file. How can I do that?

Upvotes: 0

Views: 121

Answers (1)

TheMaster
TheMaster

Reputation: 50383

You need to create a tsconfig.json in the project directory for tsserver to recognize that both files are part of the same project. Create one like:

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "skipLibCheck": true,
    "target": "ES2022",
    "types": ["location of /node_modules/@types/google-apps-script"]
  },
  "include": ["./"],
  "exclude": []
}

The tree should look like

.
├── appsscript.json
├── a.js
├── b.js
├── tsconfig.json

Upvotes: 3

Related Questions