Skip to content

Global type scope polution in VS Code #2800

@colecrouter

Description

@colecrouter

When working in nested directories/projects, it's possible to define code where certain libs are omitted:

// src/lib/other/tsconfig.json
{
    "compilerOptions": {
        "lib": ["ES2020"],
        "types": [],
    },
}

Imagine your Svelte codebase has a service worker, and you want to exclude lib.dom.d.ts in related code. Svelte obviously requires lib.dom.d.ts, but by using another tsconfig (like above) tsc enforces this as desired. VS Code, however, does not, when using Svelte for VS Code. If you disable the extension, it works fine.

From the logs, you can see that the extension "injects" several libs:

Info 85   [11:59:08.356] event:
    {"seq":0,"type":"event","event":"createFileWatcher","body":{"id":20,"path":"path/to/root/node_modules/svelte/types/package.json"}}
Info 86   [11:59:08.356] Finishing updateGraphWorker: Project: path/to/nested/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed: 553.7230999999999ms
Info 87   [11:59:08.356] Project 'path/to/nested/tsconfig.json' (Configured)
Info 88   [11:59:08.359] 	Files (56)
	Microsoft VS Code/resources/app/extensions/node_modules/typescript/lib/lib.dom.d.ts
...

—in turn, this seems to make all TS/JS code that is a descendent of any folder containing a node_modules/svelte automatically include all of those declarations (as far as VS Code is concerned).

For .svelte code, this makes sense, but for plain TS/JS, would it be at all possible to omit/ignore/exclude these from syntax checking? (either implicitly or explicity)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions