Description
Describe the problem
ESLint is not able to run type-checked rules on values imported from .svelte
files.
<!-- baz.svelte -->
<script lang="ts" module>
export const baz = 1;
</script>
// test.ts
import { baz } from './baz.svelte';
const c = baz + 1;
Will give the following error when running ESLint with the recommended type-checked rules on test.ts
:
2:7 error Unsafe assignment of an error typed value @typescript-eslint/no-unsafe-assignment
There is a package typescript-eslint-parser-for-extra-files that aims to solve this issue, but I cannot get it to work.
Is there anything Svelte can do to help with this issue?
Describe the proposed solution
I have some ideas, but not sure if they are viable:
- Get
typescript-eslint-parser-for-extra-files
to work. Maybe there is just a configuration issue? I've done my best to try everyhting, but if someone knows how to do it then problem solved :) - The Svelte community gets together to fix
typescript-eslint-parser-for-extra-files
or fix the issue in some other way. Maybe it can be fixed as part ofeslint-plugin-svelte
orsvelte-eslint-parser
? - Let Svelte generate some code providing the types. For example, the error disappears when I have the following code in my code base. But not sure if this can be done in a way that works regardles of the import path (this will only fix it when importing from
'./baz.svelte'
, not from for example'$lib/baz.svelte'
).
declare module './baz.svelte' {
export const baz: number;
}
- Don't export anything from
.svelte
files. Instead create a sibling.ts
file with the export and import in into both the.svelte
file and the other files. I don't think this will always be possible or viable, for example it would at best be cumbersome with snippets usingcreateRawSnippet
. - Somehow disable the type checked rules on values imported from
.svelte
files.
Importance
would make my life easier