@@ -7,6 +7,7 @@ import type {
77import type { H3EventContext } from 'h3'
88import type { NitroRouteConfig as NitroRouteConfigPack , NitroRouteRules as NitroRouteRulesPack } from 'nitropack'
99import type { NitroRouteConfig , NitroRouteRules , NitroRuntimeHooks } from 'nitropack/types'
10+ import type { NuxtConfig } from 'nuxt/schema'
1011import type { PageMeta } from '#app'
1112import { extendRouteRules } from '@nuxt/kit'
1213import { describe , expectTypeOf , it } from 'vitest'
@@ -65,6 +66,19 @@ describe('nitropack augmentations (cross-module-path)', () => {
6566 } )
6667} )
6768
69+ // Regression test for https://github.com/nuxt-modules/robots/issues/299
70+ // `nuxt.config.ts` routeRules are typed via `NuxtConfig['routeRules']`,
71+ // which (in Nuxt 4) resolves NitroRouteConfig through 'nitropack/types'.
72+ // If only 'nitropack' is augmented, declaring `robots` in routeRules fails
73+ // with TS2353 "Object literal may only specify known properties".
74+ describe ( 'NuxtConfig routeRules (issue #299)' , ( ) => {
75+ it ( 'NuxtConfig.routeRules accepts a robots-tagged literal' , ( ) => {
76+ expectTypeOf < { '/admin' : { robots : false } } > ( ) . toExtend < NonNullable < NuxtConfig [ 'routeRules' ] > > ( )
77+ expectTypeOf < { '/private' : { robots : 'noindex, nofollow' } } > ( ) . toExtend < NonNullable < NuxtConfig [ 'routeRules' ] > > ( )
78+ expectTypeOf < { '/legacy' : { robots : { indexable : false , rule : 'noindex' } } } > ( ) . toExtend < NonNullable < NuxtConfig [ 'routeRules' ] > > ( )
79+ } )
80+ } )
81+
6882describe ( 'h3 augmentations' , ( ) => {
6983 it ( 'H3EventContext.robots is RobotsContext' , ( ) => {
7084 expectTypeOf < H3EventContext [ 'robots' ] > ( ) . toEqualTypeOf < RobotsContext > ( )
0 commit comments