Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seemingly unable to exclude node_modules from svelte-check pass #2514

Open
webJose opened this issue Sep 25, 2024 · 7 comments
Open

Seemingly unable to exclude node_modules from svelte-check pass #2514

webJose opened this issue Sep 25, 2024 · 7 comments
Labels
question Further information is requested

Comments

@webJose
Copy link

webJose commented Sep 25, 2024

Describe the bug

Maybe this is not a bug, and maybe it is just me unable to configure things properly. Since I have struggled with this for a couple of hours already, I'll venture myself and post it as a bug. If you know better, please, by all means correct me.

I want to set skipLibCheck: false in my tsconfig.json file because I am declaring some modules in .d.ts files and I want them checked. Doing this certainly makes VS Code correct my mistakes. Good. However, svelte-check, when run, checks the d.ts files inside node_modules. I have tried many variations for excluding the node_modules folder without success.

  1. skipLibCheck: false, exclude: [ "node_modules" ]
  2. skipLibCheck: false, exclude: [ "node_modules/" ]
  3. skipLibCheck: false, exclude: [ "./node_modules" ]
  4. skipLibCheck: false, exclude: [ "./node_modules/" ]
  5. skipLibCheck: false, exclude: [ "./node_modules/*" ]
  6. skipLibCheck: false, exclude: [ "./node_modules/**" ]
  7. skipLibCheck: false, exclude: [ "node_modules/**" ]
  8. skipLibCheck: false, exclude: [ "node_modules/**/*.d.ts" ]

And the list goes on and on.

Reproduction

  1. npm create vite@latest. Select Svelte, then Typescript.
  2. npm install svelte@next svelte-check@4
  3. Modify tsconfig.json with skipLibCheck: false and your favorite version of exclude.

Let me know how it goes. For me, it complains about node_modules/svelte/types/index.d.ts and node_modules/svelte-check/dist/src/svelte-shims-v4.d.ts.

Expected behaviour

No definition files are checked inside the node_modules folder.

System Info

  • OS: Windows
  • IDE: VS Code

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

No response

@webJose webJose added the bug Something isn't working label Sep 25, 2024
@jasonlyu123
Copy link
Member

exclude doesn't prevent files from being checked it only prevents them from being loaded as entry files. All files loaded either as entry files or because of an import will be checked. This is the behaviour of tsc as well so we are unlikely to change this. There is a proposal in the TypeScript repo to add a flag only to disable .d.ts check in node_modules but it was a couple of years ago and doesn't seem to be on track to be implemented.

Can you share what kind of .d.ts file you want to check? If it's just some types you can just use the ts file instead and it'll be checked. That also work if you plan on using JSDoc in case that is why you use .d.ts instead of a regular ts file.

@jasonlyu123 jasonlyu123 added question Further information is requested and removed bug Something isn't working labels Sep 25, 2024
@webJose
Copy link
Author

webJose commented Sep 25, 2024

I need to create ambient modules:

declare module "@scope/utility-module" {
    ...
}

These are modules exported by micro-frontends that are then consumed by other micro-frontends. All these are externalized, and then defined in an import map.

@jasonlyu123
Copy link
Member

That should work in a ts file as well. But if the module has an import map why do you have to declare it manually? Is there any error that can't be fixed in the @scope/utility-module module? Or maybe your module resolution isn't bundler or nodenext?

@webJose
Copy link
Author

webJose commented Sep 26, 2024

The d.ts file is for Intellisense support. If not included, VS Code will report "could not find module definition or its declaration", or something like that.

@jasonlyu123
Copy link
Member

Oh right, it's import map, not export map. You do need the "declare module" or define it in the "paths" config. But yeah you can also use "define module" in a ts file so you don't disable skipLibCheck.

@webJose
Copy link
Author

webJose commented Sep 26, 2024

Ok, thanks. So long story short: The exclude property in tsconfig.json is only for a subset of the TypeScript functionality and it doesn't cover type checking. Svelte tooling has no saying about this (currently or in the future?) and we are at the mercy of Microsoft.

Accurate?

@jasonlyu123
Copy link
Member

jasonlyu123 commented Sep 26, 2024

It is a common misunderstanding. It's just not what the config is meant for. https://www.typescriptlang.org/tsconfig/#exclude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants