-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(kit): provide type support for module options in installModule
#26744
base: main
Are you sure you want to change the base?
Conversation
Run & review this pull request in StackBlitz Codeflow. |
installModule
@@ -41,6 +41,15 @@ export default defineNuxtConfig({ | |||
filename: 'test.d.ts', | |||
getContents: () => 'declare type Fromage = "cheese"', | |||
}) | |||
function _test () { | |||
installModule('~/modules/example', { |
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the dynamic import https://github.com/nuxt/nuxt/pull/26744/files#diff-84e752bfeb5965269318fc84ddc24d24fa76cdca52fcc7d4e61f9ea5e7efae21R17 ends up using NuxtConfig
from @nuxt/schema
instead of nuxt/schema
after build, but nuxt/schema
is augmented by the generated types https://github.com/nuxt/nuxt/pull/26744/files#diff-2176c7ab69dcd5ffc94e79963693b007471788f25591aeb72e7533240ebad2c2R168.
If you use a type import instead of the dynamic import and set nuxt/schema
as external it seems to work as expected, but I have no idea if this has other unintended results.
I couldn't open a PR on your branch for some reason so you can check out my changes in this commit instead BobbieGoede/nuxt@f1ba5e1
(#5).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely amazing ❤️
🔗 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: