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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kit): provide type support for module options in installModule #26744

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ineshbose
Copy link
Member

@ineshbose ineshbose commented Apr 11, 2024

馃敆 Linked issue

馃摎 Description

These changes relies and builds on top of #18416 (my first PR on Nuxt 馃槃); it extracts the options from there after module authors run prepare.

Try this in the repo playground:

import { installModule } from "@nuxt/kit";

installModule('@nuxt/devtools', { customTabs: [] })

Copy link

stackblitz bot commented Apr 11, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@danielroe danielroe changed the title chore(kit): provide type support for module options in installModule feat(kit): provide type support for module options in installModule Apr 12, 2024
@@ -41,6 +41,15 @@ export default defineNuxtConfig({
filename: 'test.d.ts',
getContents: () => 'declare type Fromage = "cheese"',
})
function _test () {
installModule('~/modules/example', {
Copy link
Member Author

Choose a reason for hiding this comment

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

this doesn't seem to be picking up because .nuxt/types/schema.d.ts now seems to be using resolved paths, i.e.

declare module 'nuxt/schema' {
  interface NuxtConfig {
    modules?: (["/home/nuxt/nuxt/test/fixtures/basic-types/modules/example", Exclude<NuxtConfig["sampleModule"], boolean>] | ["@nuxt/devtools", Exclude<NuxtConfig["devtools"], boolean>])[],
  }
}

so where T = '~/modules/example', it is not equal to /home/nuxt/nuxt/test/fixtures/basic-types/modules/example; so this will work for package names more than local modules, sure, but I'm not sure how the usage ahead of ['~/modules/example, { typeTest: () {} }] worked even when the path isn't same 馃

Copy link
Member Author

Choose a reason for hiding this comment

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

but I'm not sure how the usage ahead of ['~/modules/example, { typeTest: () {} }] worked even when the path isn't same

it's likely that its just the TypeScript is quite relaxed with all the union options.

Copy link
Member Author

@ineshbose ineshbose Apr 13, 2024

Choose a reason for hiding this comment

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

it should work now; also note that (as I had thought), we're doing a dynamic import of NuxtConfig within types (edit: CI still failing... hmm)

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