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
Pinia, when it produces type of the store variable, doesn't stop recursive ref flattening when it encounters ShallowRef<X> and continues to flatten X recursively producing store type that doesn't match its runtime value
Additional information
This works correctly when using option store API. Proof
The text was updated successfully, but these errors were encountered:
bgoscinski
changed the title
Incorrect types for stores that consist of ShallowRef<{ foo: Ref<...> }>
Incorrect types for stores that consist of ShallowRef<{ bar: Ref<...> }>Sep 11, 2024
bgoscinski
changed the title
Incorrect types for stores that consist of ShallowRef<{ bar: Ref<...> }>
Incorrect types for setup stores that consist of ShallowRef<{ bar: Ref<...> }>Sep 11, 2024
bgoscinski
changed the title
Incorrect types for setup stores that consist of ShallowRef<{ bar: Ref<...> }>
Incorrect types for setup stores that contain ShallowRef<{ bar: Ref<...> }>Sep 11, 2024
A workaround is to either
A) use options store instead of setup store
B) lie in TS like so:
constuseStore=defineStore('test',()=>{constfoo=shallowRef({bar: ref('baz')})// ^^^ this is ShallowRef<{ bar: Ref<string> }>return{foo: fooasunknownasShallowRef<typeoffoo>// ^^^^^^^^^^ introduce another layer of ShallowRef// this makes pinia believe that foo is// ShallowRef<ShallowRef<{ bar: Ref<string> }>>}})
This works because pinia applies UnwrapRef type to the state twice so when it encounters ShallowRef<ShallowRef<T>> it'll flatten it to T.
Reproduction
https://play.pinia.vuejs.org/#eNqtVFFv2jAQ/itWXqAS2KvoOgkBYpv6sD1sVdvHaFKID+IusS3bSekQ/31nJ4FAKWLSIkDO3Xf3fXe+YxN91ppWJUTjaGJTI7QjeSJX0zhyNo5msRSFVsaRDeGwFBIenTJAtmRpVEF6WkiR9DogmyV5rl4eYDkgxv8Ii+cdHokQHctUSetIaZt0027yfs+Bdb0B6V+R6YxsYkkwlSuNJP0NWSo17rCgZZGYsefq9xbJn94V2fpPLP13wuqSsAx8acqzmEsfFVnrsY2YVlcfU7S+BO3uVYNa1jCKQihSt/7FO35aJXkJsWSMnHt++Yc8PZJUFTpPhLRkUToiUFSmypzLnmuZ0rNMNAe5ctn/JORIGK6xf8D3pr8OfCYH+EbIhItqdu/HI4i1JBdAXJb4/O3lWZJgv0v5YhKtgQcBCDCldKLwaHj1CJRCMpApeLlgjDJ2wnz6wKMNzE61g0ynUxJHmw1e3XYbRxPmkWdD6g7uAxf/Fti0fh+fnoo/1cl9CD8ImbBOT6NBVK/ZsEg0fbZK4s6G7YgbB87yuN4Xbwu76S1xxMKZgi2GC6NeLBiMj6NBC53jXjIOlVMqt8NEizosc07bMWMpl4jnkIvKUAmOSV2wNzHzW3pLr1kuFgyJmJAc1oc0GDHkUFySvYXOP9DrG/opZK1GTdLiOOulcpvJGnJVzEf0I73BMbKua36/Rz4ejRWYIY4kBwPmUtqjsC71kesNvWff4p8ZXr6zuI5LsTq6er+/IgfzUzuB63owAmHRvgebMyXsakkzSH+fsD/bdV3TvYGgrFO/S8wKXO2+e/wBazzvnIXiZd5cwzvOB7AqL73GGvallBxld3BB7bcwyUKunuzd2oG0bVFeaOhGwIf7+Hqm9L3cER3turj9C5toUtQ=
Steps to reproduce the bug
Expected behavior
Pinia types properly stop recursive flattening of the types upon encountering
ShallowRef<X>
so thatActual behavior
Pinia, when it produces type of the store variable, doesn't stop recursive ref flattening when it encounters
ShallowRef<X>
and continues to flattenX
recursively producing store type that doesn't match its runtime valueAdditional information
This works correctly when using option store API. Proof
The text was updated successfully, but these errors were encountered: