seems like something is perhaps broken using svelte v5 with eslint rules (with type checking enabled):
(start with minimal app e.g. npx sv create foo (typescript + eslint)
)
minimally change eslint.config.js
to add typed rules:
import js from '@eslint/js';import svelte from 'eslint-plugin-svelte';import globals from 'globals';import ts from 'typescript-eslint';export default ts.config( { ignores: ['*.config.js'], }, js.configs.recommended, ...ts.configs.recommendedTypeChecked, // *** changed ...svelte.configs['flat/recommended'], { languageOptions: { globals: { ...globals.browser, ...globals.node, }, // *** ADDED parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname, extraFileExtensions: ['.svelte'], }, }, }, { files: ['**/*.svelte'], languageOptions: { parserOptions: { parser: ts.parser, }, }, }, { ignores: ['build/', '.svelte-kit/', 'dist/'], });
Although tsc
has no problems (it knows the type of id
is string
, eslint doesn't seem to pick up sveltekit-generated types:
BTW, this does work:
import { json } from '@sveltejs/kit';import type { RequestHandler } from './$types';export const GET: RequestHandler = ({ params: { id } }) => { return json({ id });};
But shouldn't be necessary and is a regression in DX IMO. This all worked well in svelte 4 + eslint 8, but I don't know which upgrade causes this new problem.
Advice/help appreciated!