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(nuxt): exclude plugin declaration from non-existent files #20974

Merged
merged 1 commit into from May 20, 2023

Conversation

danielroe
Copy link
Member

πŸ”— 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

This PR fixes an issue where non-existent (i.e. virtual) plugins would cause type inference for plugin injections to fail.

πŸ“ Checklist

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

@danielroe danielroe self-assigned this May 20, 2023
@danielroe danielroe merged commit 957a75a into main May 20, 2023
19 checks passed
@danielroe danielroe deleted the fix/plugin-injections branch May 20, 2023 22:14
This was referenced May 20, 2023
@IlyaSemenov
Copy link

I was wondering if this could be somehow backported to 3.4.x with some kind of user-land code? Type inference breaks in <3.5.1 due to InjectionType<typeof import("../components.plugin").default> which is fixed here.

@IlyaSemenov
Copy link

OK, it was actually simple:

// Fix useNuxtApp() return type missing data injected by plugins.
//
// The problem was fixed in Nuxt 3.5.1, please remove after upgrading.
// See https://github.com/nuxt/nuxt/pull/20974#issuecomment-1592724945

import { addTemplate, defineNuxtModule } from '@nuxt/kit'

export default defineNuxtModule({
  setup(_option, nuxt) {
    addTemplate({
      getContents: () =>
        'declare const _default: any; export default _default;',
      filename: 'components.plugin.d.ts',
      dst: nuxt.options.buildDir + '/components.plugin.d.ts',
      write: true,
    })
  },
})

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

2 participants