-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
feat: resolve Svelte components using TS from exports map #2478
base: master
Are you sure you want to change the base?
Conversation
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
Mhm not sure why this fails - works locally for me (Windows) |
I didn't see the package.json with exportMap. Maybe it's ignored because of gitignore? About |
Doh, you're right, the node modules folder isn't checked in. |
…ke `./foo.svelte` make .svelte query before .svelte.ts
I realized that since 5.0, TypeScript will check for
|
Having second thoughts about this - should we really do this? It could encourage bad patterns. On the other hand we could also embrace it - I'm not sure. This needs discussion with other maintainers. Implementation-wise I noticed that the TS plugin does throw an error: I'm gonna split out the other changes to land them and put this into draft. |
This change allows people to write export maps using only a
svelte
condition (and notypes
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:
customConditions: ['svelte']
to the compiler options, so that TypeScript's resolution algorithm takes it into accountensure that Svelte files have a module kind of ESM, so that TypeScript's resolution algorithm goes into the right branchesno longer needed since the switch to using.d.svelte.ts
as the "virtual file check" entry point.d.svelte.ts
files in the context of an exports map, because that's what TypeScript will try to resolve this to in the endThis 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
As a side effect, this is a major version bump for language-tools and the typescript plugin, and consequently for svelte-check/vs code extension