You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When declaring a derived store that has null as the initial value and has two or more stores as dependencies, I can't specify
the type that the derived store contains without first having so specify the type of the dependency array, which is somewhat frustrating.
// ideal situation (does not currently work)// the type of the the store's value is `DerivedData | null`// and the type of the dependecies is inferredconstmyData=derived<DerivedData|null>([a,b,c],([$a,$b,$c],set)=>{if(!$a||!$b||!$c){set(null);return;}const{ data, dispose }=generateData($a,$b,$c);set(data);returndispose;});// reality// one way to work around the problem// manually typing the `set` parameter will yield the same result, but it's more verboseconstmyData=derived([a,b,c],([$a,$b,$c],set: (value: DerivedData|null)=>void)=>{if(!$a||!$b||!$c){set(null);return;}const{ data, dispose }=generateData($a,$b,$c);set(data);returndispose;});// another workaround// like before, it yields the same result, but it's also more verbose than it should beconstdeps=[a,b,c]asconstconstmyData=derived<typeofdeps,DerivedData|null>(deps,([$a,$b,$c],set)=>{if(!$a||!$b||!$c){set(null);return;}const{ data, dispose }=generateData($a,$b,$c);set(data);returndispose;});
Describe the proposed solution
Swapping the order of the generic parameters of the derived function would solve the problem.
This would be a breaking change, but even if we swapped the order I don't think it would help because you can't just omit the second parameter to let it be inferred. Probably blocked by microsoft/TypeScript#26349
Sorry, does this mean stores are effectively deprecated? If they're not being updated and are replaced by $state, it sure seems that way.
Or are they just considered stable and not being removed, but not being updated? I don't know why they'd need to stay, but the docs say they're staying so I just wanted to clear that up.
Describe the problem
When declaring a derived store that has
null
as the initial value and has two or more stores as dependencies, I can't specifythe type that the derived store contains without first having so specify the type of the dependency array, which is somewhat frustrating.
Describe the proposed solution
Swapping the order of the generic parameters of the
derived
function would solve the problem.svelte/packages/svelte/src/runtime/store/index.js
Lines 124 to 132 in f4c4d99
Alternatives considered
The alternatives were listed above.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: