A `store` of type `Readable<number> | undefined` generates `$store: number | undefined` even when inside a guarding `if(store)`
See original GitHub issueDescribe the bug
Let’s say we have a store: Readable<number> | undefined
. Inside a guarded if (store)
-block, $store
should be of type number
, but currently it is number | undefined
.
To Reproduce
<script lang="ts">
import { readable, Readable } from "svelte/store";
let store: Readable<number> | undefined;
if (!store) {
store = readable(42);
} else {
const storeValue: number = $store;
// fails with:
// Type 'number | undefined' is not assignable to type 'number'.
// Type 'undefined' is not assignable to type 'number'.ts(2322)
}
</script>
Expected behavior
The type of $store
should be number
when guarded with if (store)
.
System (please complete the following information):
"svelte-check": "^2.3.0"
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
type 'number | undefined' is not assignable to type 'number'. type ...
Let's say we have a store: Readable<number> | undefined . Inside a guarded if (store) -block, $store should be of type number ,...
Read more >NuxtJS store returning local storage values as undefined
The values exist in local storage however the store returns it as undefined. If I render the values in the ui with {{value}}...
Read more >LaTeX Error: Environment split undefined - Resurchify
For example, the align environment. The align environment is a part of amsmath package. So, if you want to use the align environment,...
Read more >Guardianship of Adults, P-20460
A. What findings must a court make in deciding whether to appoint a guardian for an adult based on a finding of incompetence?...
Read more >Untitled - ResearchGate
I think that Esgar creates as if making images bloom, because of the profusion ... concert halls, recording studios, record stores, SubPop label, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Btw I think it’s a regression. The problem suddenly appeared in our codebase when I returned from PTO. Some change between middle December and now?
Then, the button would only be shown if it was enabled, because a disabled button returns
false
. I’d have to writewhen I want to show a button depending on whether a store was supplied or not.