vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
12.91k stars 1.02k forks source link

`storeToRefs` loses the original typings of refs/computeds in a setup store, "generalizes" them instead #2574

Closed Anoesj closed 4 months ago

Anoesj commented 7 months ago

Reproduction

https://play.pinia.vuejs.org/#eNqlV9ty2zYQ/RVUD5Xk2GSstJmpTDlOO0nGfUgysdI8RJmaIkEJNgVwAFC2R9W/9yxA0qTkOm7rF4GLvZy9Yr3pvS6KYF3y3rgXmUSLwjLDbVmwPJaLyaxnzax3OpNiVSht2YYZqzSfqk88M2zLMq1WrF8IKeL+SYurNPyCGBuWIExUKS3XgTX9mZzJMGTTpTBszbURSrJUccOkskzzLOeJZXbJWZzYMs6ZvStwqTK6M6Q7ZUI6BocmqLTFtm/YzfKOTS+YWaobw2LJuNZKMxjIheTsF/AmSho4SZLHbNJAHQzrqw2TYyaPgX3SdnfgRYbw0/Npjki9Jx3yOHAfuHrYsx86ZkePmB09bHY0ZDFcl9dS3Ug6nsuM6w9aLISMc/BNKUYRRQpx8iKnO0jJrBw1SKPQ5xvZxYflqyKPLccXY1HhfhgcG/tDNC+thTNnSS6Sa9SFPH72DJVxLhPNV1wCPvAjZtso9KyVhj3BKmqQ/USnDnsUesP39kf/aH/0gH0E74n2R4/Yj8ImGL3Dnq/po1VcBFdGSfTJhlhn1QXaY8wchWiuE4gy64XuHHCzOpprFCNK/wrMhzXrGZouTPnaKpWbo7gQXmxpbWHGYZikEvwpz8VaB5LbUBarcE/m7GXwc3Ac5mIewlAoZMpvu2YgcZTy1VO016xnz4Pjn4KXTuv6RaV0RVpJ6XYmtwiLNSitTCx2gpKoVSFyVGZhUfvd4MR5rm5+dzSrS95ATJY8uX6AfmVuPeqPlDO95i23bKwX3PrrNxfv+S3OzeVKpWUO7kcukXuVl4TRs/1ayhSwW3wO7bnLsZCLqXlza7mkhm6Aumg4fhfm3x5x/R7ui+BFK4r3QxEhbKZnyjMMq+4A9TO2NWJdHdt4Tr5krTnbodNQnkl+62T8LGhG86RtZ9B3M6N/yAZDNjn1yL2ABGdH6eA5ZhbdazwUWtLgcv4M4VCHccctTO9DN8tZGzEi10EpKCBZnBBXS1c0BYxY3p0ypJPL1JCSaFohdWbHFfa1Eik0AlKjNCtlQlnpOkLig3Wcl3zMpsPxnsHaklcL4+wVeMhnmrYkDTmast+xUiMfPGDjLwx1n4f0yZo6QpUHr/6PC+10o07rZ+UPUgyTXnhQPS7OHJtMJqxfw+xDqyODc+xP9EzWKvFSU8apjLLBrv7B0D1t/zn2ZObD/AorQ+BD8lGrgmt7N/BmD1nfBRGlXbVjlfFWodOf5w4q7/bCMPAO1R3PGJflimsCPGZZnJt6bt1o4dzoUv2wLPf4t6S21Useha9etJN/Q9JOI7kO2jDXtofsT/f7RdjlhcWLBcJneaPj4nWe44yhpbFEuau3aLcLWu0eGiztDtxs3Zez49aMrol3XHItEhNNHf0UwfKnJmc7mCIfAkGqKtbztIrLPdqouaeHt7quaO9QGtimusTXrvQM0aq3/lW9n56nKI7K0AlI0OgI+D2hzJIyECq1J7RnkiqQKqUnNNBIJTYyjkXOBSTlSR7DzUWu5thKXeWEBweO8YB9WXKJ4Yq3gpmCJ2Jvb8XK+pFi7SEajMIlF5qYIOPcgBbSr3laJthxrWIxPhYlrLJLlMVl4DfLJc9R4b4QEuy4c+6XYqsqLXDRrceqquDaCGEhOuHBJky8lcTBwWcTL/i4cefy8hK7jT/7Ls6Uqh8OWHtbfdV9Ucth+32DxHPtF7ddYfd/Q3e/ra9qRfcSYGzLBUT63upbC5x+7ePY/7aH7sMOso2ztLt0N6D+zdrd2K49QRD9KaSf+4baU7DTQE1jDXwVPqELv+IBB7n/zUv8+DSZqhe8FCWAxs72bwrIxQM=

Steps to reproduce the bug

Use storeToRefs on a setup store, containing special kinds of refs (see reproduction). The typings of the returned refs will be "generalized" to regular Refs. The DX could be better here.

Expected behavior

storeToRefs returns the original typings of the refs/computeds in the setup store.

Actual behavior

storeToRefs returns generalized typings, even though the original refs are returned. So there's a discrepancy between what storeToRefs returns and how its return value is typed.

Additional information

Read the comments in the reproduction to better understand the issue here. I included a workaround that kind of fixes the DX issue here, but it's probably not an ideal solution :wink:.

Note that I only tested refs, not computeds specifically.