@nuxt/docs-nightly 4.0.2-29224173.3db3a78f → 4.0.2-29226089.c2c18e7e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,12 @@ import type { ModuleDefinition, ModuleOptions, NuxtModule } from '@nuxt/schema'
44
44
  export function defineNuxtModule<TOptions extends ModuleOptions> (
45
45
  definition?: ModuleDefinition<TOptions, Partial<TOptions>, false> | NuxtModule<TOptions, Partial<TOptions>, false>,
46
46
  ): NuxtModule<TOptions, TOptions, false>
47
+
48
+ export function defineNuxtModule<TOptions extends ModuleOptions> (): {
49
+ with: <TOptionsDefaults extends Partial<TOptions>> (
50
+ definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | NuxtModule<TOptions, TOptionsDefaults, true>
51
+ ) => NuxtModule<TOptions, TOptionsDefaults, true>
52
+ }
47
53
  ```
48
54
 
49
55
  ### Parameters
@@ -122,6 +128,49 @@ If the user tries to use your module with an incompatible Nuxt version, they wil
122
128
  - [nuxt] Nuxt version ^3.1.0 is required but currently using 3.0.0
123
129
  ```
124
130
 
131
+ #### Type Safety for Resolved Options with `.with()`
132
+
133
+ When you need type safety for your resolved/merged module options, you can use the `.with()` method. This enables TypeScript to properly infer the relationship between your module's defaults and the final resolved options that your setup function receives.
134
+
135
+ ```ts
136
+ import { defineNuxtModule } from '@nuxt/kit'
137
+
138
+ // Define your module options interface
139
+ interface ModuleOptions {
140
+ apiKey: string
141
+ baseURL: string
142
+ timeout?: number
143
+ retries?: number
144
+ }
145
+
146
+ export default defineNuxtModule<ModuleOptions>().with({
147
+ meta: {
148
+ name: '@nuxtjs/my-api',
149
+ configKey: 'myApi'
150
+ },
151
+ defaults: {
152
+ baseURL: 'https://api.example.com',
153
+ timeout: 5000,
154
+ retries: 3
155
+ },
156
+ setup(resolvedOptions, nuxt) {
157
+ // resolvedOptions is properly typed as:
158
+ // {
159
+ // apiKey: string // Required, no default provided
160
+ // baseURL: string // Required, has default value
161
+ // timeout: number // Optional, has default value
162
+ // retries: number // Optional, has default value
163
+ // }
164
+
165
+ console.log(resolvedOptions.baseURL) // ✅ TypeScript knows this is always defined
166
+ console.log(resolvedOptions.timeout) // ✅ TypeScript knows this is always defined
167
+ console.log(resolvedOptions.retries) // ✅ TypeScript knows this is always defined
168
+ }
169
+ })
170
+ ```
171
+
172
+ Without using `.with()`, the `resolvedOptions` parameter would be typed as the raw `ModuleOptions` interface, where `timeout` and `retries` could be `undefined` even when defaults are provided. The `.with()` method enables TypeScript to understand that default values make those properties non-optional in the resolved options.
173
+
125
174
  ## `installModule`
126
175
 
127
176
  Install specified Nuxt module programmatically. This is helpful when your module depends on other modules. You can pass the module options as an object to `inlineOptions` and they will be passed to the module's `setup` function.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "4.0.2-29224173.3db3a78f",
3
+ "version": "4.0.2-29226089.c2c18e7e",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",