Skip to content

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

Closed as not planned

Description

@xyrolle

Describe the bug

With hooks moved through the files option, svelte-check's default mode and --tsgo-experimental-api don't add the SvelteKit types to them, so an untyped handle reports implicit any. --tsgo and --incremental type it. With files.src set, no mode types the hooks or param matchers under it.

Reproduction

package.json:

{
  "private": true,
  "type": "module",
  "devDependencies": {
    "@sveltejs/kit": "2.70.3",
    "@typescript/native": "npm:typescript@7.0.2",
    "svelte": "5.57.2",
    "svelte-check": "4.7.7",
    "typescript": "6.0.3"
  }
}

svelte.config.js:

export default {
	kit: {
		files: {
			hooks: { server: 'src/server/hooks' }
		}
	}
};

tsconfig.json:

{ "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "bundler", "strict": true, "noEmit": true, "skipLibCheck": true }, "include": ["src/**/*.ts", "src/**/*.svelte"] }

src/App.svelte:

<p>app</p>

src/server/hooks.ts:

export const handle = ({ event, resolve }) => resolve(event);
npm install
npx svelte-check --tsconfig ./tsconfig.json --output machine
npx svelte-check --tsconfig ./tsconfig.json --output machine --incremental
npx svelte-check --tsconfig ./tsconfig.json --output machine --tsgo
npx svelte-check --tsconfig ./tsconfig.json --output machine --tsgo-experimental-api

Output, without the timestamps and the START lines:

# default (--tsgo-experimental-api prints the same, with "COMPLETED 2 FILES")
ERROR "src/server/hooks.ts" 1:26 "Binding element 'event' implicitly has an 'any' type."
ERROR "src/server/hooks.ts" 1:33 "Binding element 'resolve' implicitly has an 'any' type."
COMPLETED 112 FILES 2 ERRORS 0 WARNINGS 1 FILES_WITH_PROBLEMS
# --incremental and --tsgo
COMPLETED 2 FILES 0 ERRORS 0 WARNINGS 0 FILES_WITH_PROBLEMS

For files.src, change svelte.config.js to export default { kit: { files: { src: 'app' } } };, the include to ["app/**/*.ts", "app/**/*.svelte"], and move the files to:

  • app/App.svelte: <p>app</p>
  • app/hooks.server.ts: export const handle = ({ event, resolve }) => resolve(event);
  • app/params/id.ts: export const match = (param) => /^\d+$/.test(param);

All four modes then report:

ERROR "app/hooks.server.ts" 1:26 "Binding element 'event' implicitly has an 'any' type."
ERROR "app/hooks.server.ts" 1:33 "Binding element 'resolve' implicitly has an 'any' type."
ERROR "app/params/id.ts" 1:23 "Parameter 'param' implicitly has an 'any' type."

Expected behaviour

The hooks and params files at the configured locations get the same types as at the default ones.

Fix direction

One helper for all modes that reads files, derives the defaults from files.src, and resolves configured locations against the config's directory. Matching them as plain path suffixes, as the overlay modes do now, also types unrelated files (hooks.server: 'server' matches observer.ts and other/server.ts), so a configured location has to be compared as a path. #3165 does this.

System Info

  • svelte-check 4.7.7, @sveltejs/kit 2.70.3, Svelte 5.57.2, TypeScript 6.0.3, @typescript/native as npm:typescript@7.0.2
  • Node 24.16.0, macOS arm64

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

The TypeScript plugin that types .ts files in the editor has its own copy of the defaults too; I haven't looked into that one.

Activity

  1. jasonlyu123 commented on Oct 24, 2026

    @jasonlyu123
    Member

    files config is deprecated, so I would rather not touch it unless there is enough demand for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions