Skip to content

fix: type SvelteKit hooks and params files at their configured locations - #3165

Closed
xyrolle wants to merge 5 commits into
sveltejs:masterfrom
xyrolle:fix/kit-files-config
Closed

xyrolle wants to merge 5 commits into
sveltejs:masterfrom
xyrolle:fix/kit-files-config

Conversation

@xyrolle

@xyrolle xyrolle commented Oct 22, 2026 •

Copy link
Copy Markdown

Fixes #3162

svelte-check's default mode and --tsgo-experimental-api now take the hooks and params locations from the Svelte config's files option, and all modes read files.src.

What was wrong:

  • JSOrTSDocumentSnapshot read the config only for files that already matched the default locations, and then assigned with ||= over non-empty defaults, so a configured location never applied.
  • The --tsgo-experimental-api provider had its own copy of the defaults. That copy is also where fix: type hooks.server exports with --tsgo-experimental-api #3154 fixes the server hooks path, so this includes that fix; once one of them lands, I'll merge master into the other.
  • The overlay modes passed the configured strings to the matchers as path suffixes, so hooks.server: 'server' also typed observer.ts and other/server.ts.

What changed:

  • resolveKitFilesSettings (in configLoader.ts) maps files to the settings for every mode. Like SvelteKit, a location the config sets, directly or through files.src, is resolved in the config's directory. Locations the config leaves out keep the relative defaults.
  • In svelte2tsx, isHooksFile / isParamsFile compare an absolute location as a path, so only the configured location matches: not a deeper folder with the same names, another drive or share. Relative locations still match in any folder, as the defaults always have.
  • An empty string is a location (the config's directory), as in SvelteKit. Values that aren't strings are ignored, so a malformed config falls back to the defaults instead of throwing.
  • Declaration files skip the config lookup and keep the defaults. There are a lot of them in node_modules and none are hooks or param matchers, so this doesn't add a lookup per .d.ts.

Test: a DocumentSnapshot case loads a small svelte.config.js fixture (files.src: './app' and a custom server hooks path) through configLoader.loadConfigs, and checks that the hooks and params files get their types and that the same relative path inside another folder doesn't. On master it fails at "configured server hook must be typed". Root pnpm test passes. pnpm lint passes with #3161's ignore rules; without them it fails on generated files after pnpm test.

@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 190700a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
svelte2tsx Patch
svelte-language-server Patch
svelte-check Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@xyrolle

xyrolle commented Oct 24, 2026

Copy link
Copy Markdown
Author

Makes sense, since files is deprecated. Closing this; #3162 can collect demand if it comes up.

@xyrolle xyrolle closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom SvelteKit hooks and params locations (files option) aren't typed by svelte-check

1 participant