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

fix(types): handle union types in generic parameter #2794

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

jh-leong
Copy link
Member

@jh-leong jh-leong commented Oct 6, 2024

close #2785

Copy link

netlify bot commented Oct 6, 2024

Deploy Preview for pinia-playground ready!

Name Link
🔨 Latest commit da3a894
🔍 Latest deploy log https://app.netlify.com/sites/pinia-playground/deploys/67026e039ef93400081b4a35
😎 Deploy Preview https://deploy-preview-2794--pinia-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Oct 6, 2024

Deploy Preview for pinia-official canceled.

Name Link
🔨 Latest commit da3a894
🔍 Latest deploy log https://app.netlify.com/sites/pinia-official/deploys/67026e034021f0000831a0c4

Copy link

pkg-pr-new bot commented Oct 6, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@pinia/nuxt@2794
pnpm add https://pkg.pr.new/pinia@2794
pnpm add https://pkg.pr.new/@pinia/testing@2794

commit: da3a894

Copy link

codecov bot commented Oct 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.11%. Comparing base (2974e20) to head (da3a894).
Report is 1 commits behind head on v2.

Additional details and impacted files
@@            Coverage Diff             @@
##               v2    #2794      +/-   ##
==========================================
+ Coverage   89.66%   90.11%   +0.44%     
==========================================
  Files          14       14              
  Lines        1335     1335              
  Branches      219      221       +2     
==========================================
+ Hits         1197     1203       +6     
+ Misses        137      131       -6     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

export type StoreToRefs<SS extends StoreGeneric> = _ToStateRefs<SS> &
ToRefs<PiniaCustomStateProperties<StoreState<SS>>> &
_ToComputedRefs<StoreGetters<SS>>
export type StoreToRefs<SS extends StoreGeneric> = SS extends unknown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this fix the problem? Isn't x extends unknown always true? I want to add a note comment for my future self and other contributors
TS is sometimes so weird 🫠

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When conditional types act on a generic type, they become distributive when given a union type (Distributive Conditional Types).

In this case, it will always resolve to the first branch because unknown is the top type in TypeScript.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This makes me wonder if there isn't another bug up the chain of types. But this is already good enough!

@posva posva changed the title fix(types/StoreToRefs): handle union types in generic parameter fix(types): handle union types in generic parameter Oct 6, 2024
Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

export type StoreToRefs<SS extends StoreGeneric> = _ToStateRefs<SS> &
ToRefs<PiniaCustomStateProperties<StoreState<SS>>> &
_ToComputedRefs<StoreGetters<SS>>
export type StoreToRefs<SS extends StoreGeneric> = SS extends unknown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This makes me wonder if there isn't another bug up the chain of types. But this is already good enough!

@posva posva merged commit ecc7449 into vuejs:v2 Oct 6, 2024
8 checks passed
@jh-leong jh-leong deleted the fix/2785 branch October 6, 2024 15:08
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.

Common state between stores is lost if type is different
2 participants