mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
fix(nuxt): overwrite #app/defaults
rather than augmenting (#27567)
This commit is contained in:
parent
47aa6a1212
commit
fbb66c43be
@ -125,6 +125,7 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
// Add nuxt types
|
||||
nuxt.hook('prepare:types', (opts) => {
|
||||
opts.references.push({ types: 'nuxt' })
|
||||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/app-defaults.d.ts') })
|
||||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/plugins.d.ts') })
|
||||
// Add vue shim
|
||||
if (nuxt.options.typescript.shim) {
|
||||
|
@ -7,7 +7,7 @@ import escapeRE from 'escape-string-regexp'
|
||||
import { hash } from 'ohash'
|
||||
import { camelCase } from 'scule'
|
||||
import { filename } from 'pathe/utils'
|
||||
import type { NuxtTemplate } from 'nuxt/schema'
|
||||
import type { NuxtTemplate, NuxtTypeTemplate } from 'nuxt/schema'
|
||||
|
||||
import { annotatePlugins, checkForCircularDependencies } from './app'
|
||||
|
||||
@ -96,6 +96,20 @@ export const serverPluginTemplate: NuxtTemplate = {
|
||||
},
|
||||
}
|
||||
|
||||
export const appDefaults: NuxtTypeTemplate = {
|
||||
filename: 'types/app-defaults.d.ts',
|
||||
getContents: (ctx) => {
|
||||
const isV4 = ctx.nuxt.options.future.compatibilityVersion === 4
|
||||
return `
|
||||
declare module '#app/defaults' {
|
||||
type DefaultAsyncDataErrorValue = ${isV4 ? 'undefined' : 'null'}
|
||||
type DefaultAsyncDataValue = ${isV4 ? 'undefined' : 'null'}
|
||||
type DefaultErrorValue = ${isV4 ? 'undefined' : 'null'}
|
||||
type DedupeOption = ${isV4 ? '\'cancel\' | \'defer\'' : 'boolean | \'cancel\' | \'defer\''}
|
||||
}`
|
||||
},
|
||||
}
|
||||
|
||||
export const pluginsDeclaration: NuxtTemplate = {
|
||||
filename: 'types/plugins.d.ts',
|
||||
getContents: async (ctx) => {
|
||||
@ -112,8 +126,6 @@ export const pluginsDeclaration: NuxtTemplate = {
|
||||
|
||||
const pluginsName = (await annotatePlugins(ctx.nuxt, ctx.app.plugins)).filter(p => p.name).map(p => `'${p.name}'`)
|
||||
|
||||
const isV4 = ctx.nuxt.options.future.compatibilityVersion === 4
|
||||
|
||||
return `// Generated by Nuxt'
|
||||
import type { Plugin } from '#app'
|
||||
|
||||
@ -132,13 +144,6 @@ declare module '#app' {
|
||||
}
|
||||
}
|
||||
|
||||
declare module '#app/defaults' {
|
||||
type DefaultAsyncDataErrorValue = ${isV4 ? 'undefined' : 'null'}
|
||||
type DefaultAsyncDataValue = ${isV4 ? 'undefined' : 'null'}
|
||||
type DefaultErrorValue = ${isV4 ? 'undefined' : 'null'}
|
||||
type DedupeOption = ${isV4 ? '\'cancel\' | \'defer\'' : 'boolean | \'cancel\' | \'defer\''}
|
||||
}
|
||||
|
||||
declare module 'vue' {
|
||||
interface ComponentCustomProperties extends NuxtAppInjections { }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user