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): sync vue type augmentations with Vue 2.7 #19526

Merged
merged 8 commits into from Mar 16, 2023

Conversation

rchl
Copy link

@rchl rchl commented Mar 8, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Fixing an error:

../../node_modules/@nuxt/types/app/vue.d.ts:21:13 - error TS2428: All declarations of 'ComponentOptions' must have identical type parameters.

21   interface ComponentOptions<

../../node_modules/vue/types/options.d.ts:168:18 - error TS2428: All declarations of 'ComponentOptions' must have identical type parameters.

168 export interface ComponentOptions<
                     ~~~~~~~~~~~~~~~~

Note that I haven't tested this probably and I admit I don't fully understand the intentions here so this needs some testing.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Mar 8, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@rchl
Copy link
Author

rchl commented Mar 8, 2023

Might also be that it is (needs to be?) different for Vue 2.6...?

@rchl
Copy link
Author

rchl commented Mar 9, 2023

As mentioned in #9239, I've verified that this issue happens in Vue 2.7 but not in Vue 2.6.

Are we fine with going forward with types being only Vue 2.7-compatible? It might be the case already as Nuxt ships with VueRouter version that relies on Vue 2.7 and there are also issues with importing Vuex in this package when using Vue 2.6.

node_modules/@nuxt/types/app/index.d.ts:5:28 - error TS2307: Cannot find module 'vuex' or its corresponding type declarations.

5 import type { Store } from 'vuex'

So, either we just revert #9230 or take this PR which reverts the breaking change but leaves some parts of the original change or we could go with something like rchl@0feb9fe which adapts the original changes to make them Vue 2.7 compatible and preserve the functionality that it added.

danielroe
danielroe previously approved these changes Mar 15, 2023
@codecov-commenter
Copy link

Codecov Report

Patch and project coverage have no change.

Comparison is base (7576a98) 66.18% compared to head (ae3f36d) 66.18%.

❗ Current head ae3f36d differs from pull request most recent head f2a2246. Consider uploading reports for the commit f2a2246 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##              2.x   #19526   +/-   ##
=======================================
  Coverage   66.18%   66.18%           
=======================================
  Files          93       93           
  Lines        4096     4096           
  Branches     1158     1158           
=======================================
  Hits         2711     2711           
  Misses       1119     1119           
  Partials      266      266           
Flag Coverage Ξ”
unittests 66.18% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

β˜” View full report in Codecov by Sentry.
πŸ“’ Do you have feedback about the report comment? Let us know in this issue.

@rchl
Copy link
Author

rchl commented Mar 15, 2023

Just for the record (since we're discussing this in private anyway): with the current state of the code the inferring of types of properties returned from asyncData (the intent of the original #9239 fix) still doesn't work.

@danielroe
Copy link
Member

That is a different issue, and not caused by the fix I pushed here, which is correct as far as I can tell, but rather by the fact that there are other parts of these declarations that also need to be updated to work with Vue 2.7.

@rchl
Copy link
Author

rchl commented Mar 15, 2023

I know but we have two ways we can go here. Either just fix the crash or fix the crash and support inferring of asyncData return values.

The latter seems complicated and potentially risky (Vue types are a little brittle).

So IMO it's an option to just fix the crash without the support for inferring and I feel like this is much safer.

Not duplicating the asyncData properties in data has potential for breakage and in some cases different runtime behavior anyway. While in theory asyncData should always run first and set the properties on data, in practice we've seen crashes reported to Sentry when we forgot to duplicate those properties in data. This is potentially only an issue in very broken environments but still it can make a difference.

@danielroe danielroe changed the title fix(types): non-matching declaration of 'ComponentOptions' fix(types): sync vue type augmentations with Vue 2.7 Mar 16, 2023
@rchl
Copy link
Author

rchl commented Mar 16, 2023

I did a bit more than minimal testing and it appears to work nicely in TS components.
Doesn't work in JS (+JSDoc when needed) components but that's fine because it's consistent with the current behavior.

@danielroe danielroe merged commit ce1df2f into nuxt:2.x Mar 16, 2023
13 checks passed
@rchl rchl deleted the fix/vue-types branch March 16, 2023 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants