8000 fix(schema): normalise additional experimental options · nuxt/nuxt@63e0c34 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63e0c34

Browse files
committed
fix(schema): normalise additional experimental options
1 parent 6a4b723 commit 63e0c34

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

packages/schema/src/config/experimental.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ export default defineResolvers({
158158
*/
159159
treeshakeClientOnly: {
160160
async $resolve (val, get) {
161-
const isV4 = ((await get('future') as Record<string, unknown>).compatibilityVersion === 4)
161+
const isV4 = (await get('future')).compatibilityVersion === 4
162162
if (isV4 && val === false) {
163163
console.warn('Enabling `experimental.treeshakeClientOnly` in v4 compatibility mode as it will no longer be configurable in Nuxt v4.')
164164
return true
165165
}
166-
return val ?? true
166+
return typeof val === 'boolean' ? val : true
167167
},
168168
},
169169

@@ -291,12 +291,12 @@ export default defineResolvers({
291291
*/
292292
configSchema: {
293293
async $resolve (val, get) {
294-
const isV4 = ((await get('future') as Record<string, unknown>).compatibilityVersion === 4)
294+
const isV4 = (await get('future')).compatibilityVersion === 4
295295
if (isV4 && val === false) {
296296
console.warn('Enabling `experimental.configSchema` in v4 compatibility mode as it will no longer be configurable in Nuxt v4.')
297297
return true
298298
}
299-
return val ?? true
299+
return typeof val === 'boolean' ? val : true
300300
},
301301
},
302302

@@ -309,12 +309,12 @@ export default defineResolvers({
309309
*/
310310
polyfillVueUseHead: {
311311
async $resolve (val, get) {
312-
const isV4 = ((await get('future') as Record<string, unknown>).compatibilityVersion === 4)
312+
const isV4 = (await get('future')).compatibilityVersion === 4
313313
if (isV4 && val === true) {
314314
console.warn('Disabling `experimental.polyfillVueUseHead` in v4 compatibility mode as it will no longer be configurable in Nuxt v4.')
315315
return false
316316
}
317-
return val ?? false
317+
return typeof val === 'boolean' ? val : false
318318
},
319319
},
320320

@@ -324,12 +324,12 @@ export default defineResolvers({
324324
*/
325325
respectNoSSRHeader: {
326326
async $resolve (val, get) {
327-
const isV4 = ((await get('future') as Record<string, unknown>).compatibilityVersion === 4)
327+
const isV4 = (await get('future')).compatibilityVersion === 4
328328
if (isV4 && val === true) {
329329
console.warn('Disabling `experimental.respectNoSSRHeader` in v4 compatibility mode as it will no longer be configurable in Nuxt v4.')
330330
return false
331331
}
332-
return val ?? false
332+
return typeof val === 'boolean' ? val : false
333333
},
334334
},
335335

@@ -491,18 +491,22 @@ export default defineResolvers({
491491
/** @type {'undefined' | 'null'} */
492492
value: {
493493
async $resolve (val, get) {
494-
return val ?? ((await get('future') as Record<string, unknown>).compatibilityVersion === 4 ? 'undefined' : 'null')
494+
const validOptions = ['undefined', 'null'] as const
495+
type ValidOption = typeof validOptions[number]
496+
return typeof val === 'string' && validOptions.includes(val as ValidOption) ? (val as ValidOption) : ((await get('future')).compatibilityVersion === 4 ? 'undefined' : 'null')
495497
},
496498
},
497499
/** @type {'undefined' | 'null'} */
498500
errorValue: {
499501
async $resolve (val, get) {
500-
return val ?? ((await get('future') as Record<string, unknown>).compatibilityVersion === 4 ? 'undefined' : 'null')
502+
const validOptions = ['undefined', 'null'] as const
503+
type ValidOption = typeof validOptions[number]
504+
return typeof val === 'string' && validOptions.includes(val as ValidOption) ? (val as ValidOption) : ((await get('future')).compatibilityVersion === 4 ? 'undefined' : 'null')
501505
},
502506
},
503507
deep: {
504508
async $resolve (val, get) {
505-
return val ?? !((await get('future') as Record<string, unknown>).compatibilityVersion === 4)
509+
return typeof val === 'boolean' ? val : ((await get('future')).compatibilityVersion !== 4)
506510
},
507511
},
508512
},
@@ -533,7 +537,7 @@ export default defineResolvers({
533537
*/
534538
compileTemplate: {
535539
async $resolve (val, get) {
536-
return val ?? ((await get('future') as Record<string, unknown>).compatibilityVersion !== 4)
540+
return typeof val === 'boolean' ? val : ((await get('future')).compatibilityVersion !== 4)
537541
},
538542
},
539543

@@ -546,7 +550,7 @@ export default defineResolvers({
546550
*/
547551
templateUtils: {
548552
async $resolve (val, get) {
549-
return val ?? ((await get('future') as Record<string, unknown>).compatibilityVersion !== 4)
553+
return typeof val === 'boolean' ? val : ((await get('future')).compatibilityVersion !== 4)
550554
},
551555
},
552556

@@ -558,7 +562,7 @@ export default defineResolvers({
558562
*/
559563
relativeWatchPaths: {
560564
async $resolve (val, get) {
561-
return val ?? ((await get('future') as Record<string, unknown>).compatibilityVersion !== 4)
565+
return typeof val === 'boolean' ? val : ((await get('future')).compatibilityVersion !== 4)
562566
},
563567
},
564568

@@ -568,7 +572,7 @@ export default defineResolvers({
568572
*/
569573
resetAsyncDataToUndefined: {
570574
async $resolve (val, get) {
571-
return val ?? ((await get('future') as Record<string, unknown>).compatibilityVersion !== 4)
575+
return typeof val === 'boolean' ? val : ((await get('future')).compatibilityVersion !== 4)
572576
},
573577
},
574578

@@ -606,7 +610,7 @@ export default defineResolvers({
606610
$resolve: async (val, get) => {
607611
const validOptions = ['body', 'within'] as const
608612
type SpaLoadingTemplateLocation = typeof validOptions[number]
609-
return typeof val === 'string' && validOptions.includes(val as SpaLoadingTemplateLocation) ? val as SpaLoadingTemplateLocation : (((await get('future')).compatibilityVersion === 4) ? 'body' : 'within')
613+
return typeof val === 'string' && validOptions.includes(val as SpaLoadingTemplateLocation) ? val as SpaLoadingTemplateLocation : ((await get('future')).compatibilityVersion === 4 ? 'body' : 'within')
610614
},
611615
},
612616

0 commit comments

Comments
 (0)
0