-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
Difference between how Svelte and JS imports from node_modules are handled #1056
Comments
Is there a possible workaround for this in the meantime? It's hard to take advantage of |
If you don't use the |
So I currently have two options:
Correct? |
Yes. You could check |
node_modules are considered read-only and unchangeable, so they should not be diagnosed. Make an exception for src/node_modules as this is a Sapper convention sveltejs#1056, sveltejs#1100
node_modules are considered read-only and unchangeable, so they should not be diagnosed. Make an exception for src/node_modules as this is a Sapper convention #1056, #1100 Co-authored-by: cor <[email protected]>
Is there any workaround for this yet, or are the only two options what @cor mentioned? |
Could you specify what your problem is? Files inside node_modules shouldn't get diagnosed anymore. |
I'm running Logs
|
The diagnostics you get from |
Previously, only TS diagnostics were omitted sveltejs#1056
Previously, only TS diagnostics were omitted #1056
It's not necessarily a misconfiguration to have *.ts files published in dependencies, right? Perhaps we're used to see .js+.d.ts files more often, but I see no problem in publishing libraries with *.ts files (even exclusively). Also Just my 2 cents. Excellent work btw! |
Any workaround? |
This change allows people to write export maps using only a `svelte` condition (and no `types` condition) and still have the types for their components resolved (i.e. the import is found) as long as they use TypeScript (i.e. have lang="ts" attribute) inside it. This should help people using monorepo setups with strong typings and not wanting to provide d.ts files alongside. This is achieved doing three adjustments: - add `customConditions: ['svelte']` to the compiler options, so that TypeScript's resolution algorithm takes it into account - ensure that Svelte files have a module kind of ESM, so that TypeScript's resolution algorithm goes into the right branches - deal with `.d.svelte.ts` files in the context of an exports map, because that's what TypeScript will try to resolve this to in the end This is also related to #1056 insofar that we align with TypeScript for this new capability: We don't resolve the file if it's a component not using TypeScript (i.e. not having the lang="ts" tag), similar to how TypeScript does not resolve .js files within node_modules
Through #1048, I noticed there is a difference between how JS and Svelte files imported from node_modules are handled:
d.ts
file) are marked asany
which errors on strict mode (no implicit any). This means TS does not attempt to aquire the type structure from the node_modules package and also does not type-check itsvelte-loading-spinners
take advantage of this and provide TS-versions of Svelte files as types, which is dangerous.I think in the long run it would be best to align with the behavior of TypeScript here. This would probably a breaking change to some users which do deep imports of Svelte files within libraries which don't have a
.svelte.d.ts
next to them. I'm also not sure how to even achieve this as I thought this stuff is handled insidets.resolveModuleName
. As an intermediate step, we definetly need to stop type-checking stuff insidenode_modules
(also see #1100)@jasonlyu123 thoughts?
The text was updated successfully, but these errors were encountered: