Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) control flow for stores #719

Merged
merged 10 commits into from
Feb 24, 2021

Conversation

dummdidumm
Copy link
Member

#493
$store --> (__svelte_store_get(store), $store)
By using the comma operand we allow TypeScript's control flow to work. Before that, it was $store --> __svelte_store_get(store) which loses control flow info every time.

We need to wait for TS 4.2 before we can merge this because we need a not-yet-published control flow fix for this solution to work.
I tested rename, go-to-declaration, find-references, hover - all looks good. But a second look once this is finalized would be good.

Props to @GrzegorzKazana from which most of this code is - thanks!

sveltejs#493
$store --> (__svelte_store_get(store), $store)
By using the comma operand we allow TypeScript's control flow to work. Before that, it was $store --> __svelte_store_get(store) which loses control flow info every time.

Co-authored-by: GrzegorzKazana <kazana.grzegorz@gmail.com>
@dummdidumm dummdidumm marked this pull request as draft December 16, 2020 17:16
@GrzegorzKazana
Copy link
Contributor

This is great - can't wait for it to be released! 🚀
Kudos for not giving up on this approach 😅

@dummdidumm
Copy link
Member Author

dummdidumm commented Dec 16, 2020

Yes, my objection in the now closed PR of yours "this won't work because X" was actually unjustified, because my code example was wrong: It said let $bla: {...sometype} = ..., but it's let $bla = __svelte... which means TS is smart enough to defer all the type intellisense to bla. So most of your code was already right and working. And since TS 4.2 will make (get(bla), $bla).blubb possible with type narrowing (I just checked with TS nightly and can confirm it works), we can ditch the more cumbersome (get(bla), $bla.blubb)-solution.
So now we just wait 😄

@dummdidumm dummdidumm marked this pull request as ready for review February 24, 2021 10:56
@dummdidumm dummdidumm merged commit cbcbea3 into sveltejs:master Feb 24, 2021
@dummdidumm dummdidumm deleted the store-control-flow branch February 24, 2021 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants