-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Description
Describe the bug
svelte-check and typing system (both JSDoc and TS) does not report an error when a typed non-undefined store initialized without initial value.
It does not produce any typing error, although in this case the store value is undefined and does not meet the original expected type.
It leads to runtime errors, which are hard to predict, especially for people not familiar with this bug.
Reproduction
With JSDoc:
/** @type {SvelteStore<string>} */
const myStore = writable() // No error
/** @type {string} */
const myString = $myStore // No error
console.assert(typeof myString === 'string') // It fails!Same applies to TypeScript:
const myStore = writable<string>()
const myString: string = $myStoreI expect a type error when initializing the store without arguments.
Or, at least, to expand the initial type with undefined, so $myStore will be typed as string | undefined, but this could be confusing.
Logs
No response
System Info
Happens on both Svelte 4 and 5.Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels