chore: support function for compilerOptions
#2623 Dec 10, 2024chore: fix dts jsdoc test
#2572 Nov 7, 2024fix: allow JS snapshots within TS plugin
#2565 Nov 6, 2024allowJS
in their config they would get errors?(perf) WIP: TS incremental parsing
#1192 Nov 5, 2024chore: optimize svelte-check bundle size
#2544 Oct 27, 2024feat: resolve Svelte components using TS from exports map
#2478 Aug 30, 2024svelte
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
.d.svelte.ts
as the "virtual file check" entry point
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
As a side effect, this is a major version bump for language-tools and the typescript plugin, and consequently for svelte-check/vs code extensionfeat: add editor label and formatter configuration defaults
#2330 Apr 21, 2024"workbench.editor.labelFormat": "short"
"workbench.editor.customLabels.patterns": {
"**/+page.*": "${dirname}/${filename}.${extname}",
"**/+server.*": "${dirname}/${filename}.${extname}",
},
Remove <svelte:html>
for the time being
enhanced:img
tag not recognised as img
@sveltejs/enhanced-img
docs, we can style images by targeting them as img
.
https://kit.svelte.dev/docs/images#sveltejs-enhanced-img-intrinsic-dimensions
However, this shows an unused css warning when using the Svelte VSCode extension
Snippets and their argument types not correctly resolved from generic legacy components
#2716 Apr 29, 2025any
.
Reproduction
<!-- loader.svelte -->
<script lang="ts" generics="T">
interface $$Slots {
default: { value: T },
loaded: { value: T },
loading: { },
error: { error: any },
}
export let promise: Promise<T>;
</script>
{#await promise}
<slot name="loading">
Loading...
</slot>
{:then value}
<slot {value} />
<slot name="loaded" {value} />
{:catch}
Error!
{/await}
<script lang="ts">
import Loader from './loader.svelte';
const delay = (ms: number) => new Promise(resolve => setTimeout(() => resolve(ms), ms));
const promise = delay(1000).then(() => "resolved");
</script>
<Loader promise={promise}>
<!--
Error on `loading`:
Object literal may only specify known properties, and 'loading' does not exist
in type '{ promise: Promise<string>; } & { children?: any; }'. ts(2353)
-->
{#snippet loading()}
Loading text...
{/snippet}
<!--
Error on `value`:
<!-- Binding element 'value' implicitly has an 'any' type. ts(7031)
-->
{#snippet loaded({ value })}
Text: {value}
{/snippet}
{#snippet error()}
Error.
{/snippet}
</Loader>
(The runtime behavior is correct.)
Expected behaviour
loading
is detected as a valid slot/snippet.
value
is generically typed correctly (here string
).
System Info
OS: Windows 10, 64bit
IDE: VSCode 1.98.2
Which package is the issue about?
Svelte for VS Code extension
Additional Information, eg. Screenshots
Extension & svelte-check
yield same errors.
If the loading
snippet is not there, the next snippet will show an error, only promise
& children
are detected as valid properties.Auto import rune files (.svelte.js
/.svelte.ts
) files with full extension.
.svelte.js
file is selected from a suggestion dropdown in VS Code, the added import lacks the .js
extension.
If the extension is missing, this can cause conflicts with components that share the prefix, it also is plain confusing to the uninitiated since it looks like a component is being imported.
Proposed solution
Always import as .svelte.js
, not sure if this is possible though.
(Maybe use .svelte.ts
if state of TS's allowImportingTsExtensions
can be detected.)
Alternatives
No response
Additional Information, eg. Screenshots
No response@link
tags don't work in .svelte
files
@link
tags are no longer clickable links when rendered to their tooltip within a .svelte
file.
Reproduction
The following interface:
interface FooBar {
foo: 1
bar: 2
/**
* Sum of {@link foo} and {@link bar}
*/
foo_bar: 3
}
When placed (or imported) into a .svelte
file, no longer shows clickable links.
.ts
file, foo
and bar
are clickable links:
rename --preserveWatchOutput
to --preserve-watch-output
--compiler-warnings
and --diagnostic-sources
breaking: use parseArgs
from Node 18.3
svelte-check
when bumping engines
to 18.3
Proposed solution
import { parseArgs } from 'node:util';
Alternatives
No response
Additional Information, eg. Screenshots
No responsePerformance: skip jsdoc parsing in various places
#2170 Sep 1, 2024Quick fix for adding $state(...)
wrapper.
non_reactive_update
would be useful.
E.g. adding the first $state
will highlight all issues on other variables:
<script lang="ts">
let a = $state(1);
let b = 2; // "`b` is updated, but is not declared with `$state(...)`. ..."
let c: number; // "`c` is updated, but is not declared with `$state(...)`. ..."
</script>
<!-- [bind to/update values] -->
Proposed solution
Add quick fix options that add $state
to the currently highlighted or all variables with the warning.
Add $state(...)
Add $state(...)
for all
<script lang="ts">
let a = $state(1);
- let b = 2;
+ let b = $state(2);
- let c: number;
+ let c: number = $state();
</script>
(For c
this would be a type error, but the resolution of that should probably be up to the user. I am assuming pre-existing migration logic would be used here if possible.)
Possibly some other quick fixes/refactoring involving $derived
and $effect
could be added for $:
(legacy_reactive_statement_invalid
).
Alternatives
No response
Additional Information, eg. Screenshots
No responseZero effort type safety for inlined enhance
callback
enhance
callback could be auto typed to the SubmitFunction
type from ./$types
in +page.svelte
files.
Since typescript in the template is not supported in Svelte < 5, it would probably only be possible for projects that use Svelte 5. Or is it possible with JSDoc?
Proposed solution
Auto type the callback.
Alternatives
No response
Additional Information, eg. Screenshots
No responseEmit dts not respecting abs path
#2182 May 14, 2024emitDts
with an absolute path, and I am in a subfolder from my project it weirdly saves it to a path like this: /workspace/extractinator/workspace/extractinator/.temp
await emitDts({
svelteShimsPath: require.resolve('svelte2tsx/svelte-shims-v4.d.ts'),
declarationDir: '/workspace/extractinator/.temp',
libRoot: '/workspace/extractinator/playground',
})
Reproduction
I can provide a repo if this isn't just user error or expected - which I worry it is
Expected behaviour
It to save it at the given path
System Info
OS: ubuntu docker
IDE: vscode
Which package is the issue about?
svelte2tsx
Additional Information, eg. Screenshots
No responseSvelte 5 various tasks
#2280 Apr 25, 2024context
from SnippetBlock code, was used in an early .next version
..
Alternatives
No response
Additional Information, eg. Screenshots
No responseWeird behavior with Generics + SvelteHTMLElement
#2271 Jan 26, 2024as
and it render the correct html element) and i started experimenting with the typings to get autocompletion. I come up with this which works fine
<script lang="ts" generics="T extends keyof HTMLElementTagNameMap">
import type { SvelteHTMLElements } from 'svelte/elements';
export let as: T;
type $$Props = SvelteHTMLElements[T] & {
as: T;
};
</script>
the typecheck per se works fine but what is a bit iffy it's the autocompletion. You get autocomplete for every prop even the one that are not associated with the type T (for example you get autocomplete for type
if you use spam
for as
). I tried the same generic function in the typescript playground and it works correctly.
https://github.com/sveltejs/language-tools/assets/26281609/1bfdc057-5cb0-42f2-b3b1-d1a0a9886dc8
https://github.com/sveltejs/language-tools/assets/26281609/403a5a65-8d27-4200-b28d-9d76d895fb9d
Reproduction
go to this TS playground https://tsplay.dev/NB1Gpw
verify that autocomplete works correctly
paste the above code in a svelte component in vscode
try to import it and get autocompletion
Expected behaviour
You should only get autocompletion for the correct element
System Info
OS: Mac
IDE: VSCode
Which package is the issue about?
No response
Additional Information, eg. Screenshots
No responseConsider removing the Omit
type from the HTMLProps
type
d.ts
file in svelte2tsx
:
type HTMLProps<Property extends string, Override> =
Omit<import('svelte/elements').SvelteHTMLElements[Property], keyof Override> & Override;
Results in the data-${string}
type overriding any more narrow types like data-sveltekit-..
. In other words, I can pass an invalid value to data-sveltekit-..
and it doesn't error, because the fallback type overrides it so that any
thing is allowed.
The question now is: Should we simplify the HTMLProps
type to import('svelte/elements').SvelteHTMLElements[Property] & Override
? The one drawback is that you cannot pass properties that have conflicting types anymore. Given that you rarely want to override a type (you mainly want to add new ones), and in case you do want to override them, you mostly want to narrow them (which is fine with the simplified type, too), I lean towards making this change. @jasonlyu123 thoughts?