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

When a computed ref is present in the setup function of a Pinia store, using mapState may lead to typing errors. #2571

Closed gcaaa31928 closed 6 months ago

gcaaa31928 commented 7 months ago

Reproduction

https://play.pinia.vuejs.org/#eNqNVMFy2jAQ/RWNL4YJSGFIckiBoe3kkB7aTtNb3YOxF6LEXnkkmTDD+N+7kmwwNMzkJGv19u3Tav320eeq4tsaovtoZqGsitTCIkHGZqvaWoVsmRUye50nEV5dJdHiETMNJaBl+z1D1jRuTds1o3UmQiKRzMSBkdHOZFpWlhUpbojOGmJLUJaV0kTGyrR6sgRlDVtrVbK4kijT+FMPUht4skofIVxkqkYLmlsT94A5rCXCV0V7dFI7PN3TEcLO4wiV1oVf++jB3l0/o21tIb9nfssY57yTOOiEjNifOI1HLMb473AUcNlg2KUwpsHWGpl9loanVNnFGrc0Hk2tJLr8mJEpNJat2Pw0xW/Q5yXYDCk6E6Gbi2gUhWuPSR1/MQrpJT1b0h5Qnw+XSCJqgdsn0bO1lbkXIsuR0nIo5FZzBCuwKsWSYEJTa2UJ41yVyym/4ZNbkUtj+3EOphyvtHoz9AYvVKltgq8jKLgFPdaAOWjQH617lnZS++zscn0/PaGi8N+Xob5oDlurVGHGaSU/KrSfs7zjt3wiCrkSVEhI0rf7ryPjHMqPsHfQ5TWf3PA7z7qdtqSlY+1mgZ7fGpqatdycPb4bYFmA/lFZSVN1MgRpUai3bz5mdQ0HidkzZK/vxF/MLqj+qcG/QO9aNtUbsOH44ek77Oj7cFiqvC7agbtw+AuMKmqnMcC+1JiT7B7Oq330syxx89s87Cyg6S7lhB7/KN9m9ytfuvpR7pRPe108Ggm18MxITk0n+FLPbTSsRwe/OPGahP7Z1mzCn31wsHmfehAbt5CRkBPMF0FsSEBCEv/geniMpRTryg1CBvJtWtTArtiEOXtw4NZ7nEuPyKCdcUTNP5br+/E=

Steps to reproduce the bug

Hovering over this.a will result in the incorrect type being displayed as any. In theory, it should be number type.

Expected behavior

The type of this.a should indeed be number.

Actual behavior

The type of this.a will be any

Additional information

No response

posva commented 7 months ago

The code hasn't changed in a while so probably it broke when upgrading some dependency like ts. Feel free to submit a PR!

In the meantime, you can use a setup() to spread the store properties:

setup() {
    return {
      ...storeToRefs(useStore())
    }
  },
gcaaa31928 commented 7 months ago

Okay, I will attempt to fix this issue soon and send a pull request. Thank you!

gcaaa31928 commented 6 months ago

@posva I've already submitted a PR. Could you please review it? Thank you!