sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.21k stars 196 forks source link

svelte-check does not respect excludes when specifying a tsconfig file #1048

Closed 9ParsonsB closed 3 years ago

9ParsonsB commented 3 years ago
  • you have searched and found no existing open issue with the problem at hand
  • similar to #1038

Describe the bug svelte-check reports errors in node_modules when referencing a tsconfig - even for files that are not referenced and/or in the exclude in the tsconfig.json

To Reproduce repo

Expected behavior Files in node_modules are excluded unless explicitly referenced or included (?)

System (please complete the following information):

Additional context

dummdidumm commented 3 years ago

To me this is a bug within the svelte-loading-spinners library. It copies the unpreprocessed files written in TypeScript into dist/ts and tells TypeScript to look there for the type definitions. But within that there are no type definitions but real Svelte files, and they have import paths which are wrong because the build script apparently contains a little bug there not rewriting the import paths or something.

The tsconfig exclude does not mean that things inside node_modules are not completely excluded from the check. If a file that matches the include pattern (App.svelte) references something that matches the exclude pattern (svelte-loading-spinners), it's still included into the list of files and therefore checked. One can tell TypeScript through skipLibCheck to skip checking of d.ts files, which is mostly used to skip diagnostics on node_modules, because TypeScript will mostly see those within node_modules. But in this case real Svelte files are referenced and that skip flag does not apply. One could argue the flag should be interpreted as "also skip Svelte files inside node_modules" in the context of svelte-check but I'm not very convinced that this is a good idea yet, especially since TypeScript will also throw errors on .ts files that are wrong and inside node_modules.

So to summarize, the library in question needs to change its build output and provide real d.ts type definitions of Svelte files instead of using a hacky workaround. For now this most likely means writing these by hand, but we are working on automating this in the context of SvelteKit.