diff --git a/test/fixtures/basic/components/Nested/SugarCounter.vue b/test/fixtures/basic/components/Nested/SugarCounter.vue index 224dca4e5e..059cf8f5f2 100644 --- a/test/fixtures/basic/components/Nested/SugarCounter.vue +++ b/test/fixtures/basic/components/Nested/SugarCounter.vue @@ -1,6 +1,9 @@ diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index 884b0af074..65664c7d71 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -67,7 +67,7 @@ export default defineNuxtConfig({ }, function (_options, nuxt) { const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2'] - const stripLayout = (page: NuxtPage) => ({ + const stripLayout = (page: NuxtPage): NuxtPage => ({ ...page, children: page.children?.map(child => stripLayout(child)), name: 'internal-' + page.name, @@ -92,7 +92,7 @@ export default defineNuxtConfig({ ], hooks: { 'prepare:types' ({ tsConfig }) { - tsConfig.include = tsConfig.include.filter(i => i !== '../../../../**/*') + tsConfig.include = tsConfig.include!.filter(i => i !== '../../../../**/*') }, 'modules:done' () { addComponent({ @@ -103,7 +103,7 @@ export default defineNuxtConfig({ } }, experimental: { - inlineSSRStyles: id => !id.includes('assets.vue'), + inlineSSRStyles: id => !!id && !id.includes('assets.vue'), reactivityTransform: true, treeshakeClientOnly: true }, diff --git a/test/fixtures/basic/pages/client-only-components.vue b/test/fixtures/basic/pages/client-only-components.vue index e5e1094a92..ca18e6ef84 100644 --- a/test/fixtures/basic/pages/client-only-components.vue +++ b/test/fixtures/basic/pages/client-only-components.vue @@ -58,10 +58,13 @@ diff --git a/test/fixtures/basic/pages/useAsyncData/refresh.vue b/test/fixtures/basic/pages/useAsyncData/refresh.vue index 5f312fd434..c4cf1021d6 100644 --- a/test/fixtures/basic/pages/useAsyncData/refresh.vue +++ b/test/fixtures/basic/pages/useAsyncData/refresh.vue @@ -11,28 +11,28 @@ const { data, refresh } = await useCounter() const { data: data2, refresh: refresh2 } = await useCounter() -let inital = data.value.count +let initial = data.value!.count // Refresh on client and server side await refresh() -if (data.value.count !== inital + 1) { - throw new Error('Data not refreshed?' + data.value.count + ' : ' + data2.value.count) +if (data.value!.count !== initial + 1) { + throw new Error('Data not refreshed?' + data.value!.count + ' : ' + data2.value!.count) } -if (data.value.count !== data2.value.count) { +if (data.value!.count !== data2.value!.count) { throw new Error('AsyncData not synchronised') } -inital = data.value.count +initial = data.value!.count await refresh2() -if (data.value.count !== inital + 1) { +if (data.value!.count !== initial + 1) { throw new Error('data2 refresh not syncronised?') } -if (data.value.count !== data2.value.count) { +if (data.value!.count !== data2.value!.count) { throw new Error('AsyncData not synchronised') } diff --git a/test/fixtures/basic/types.ts b/test/fixtures/basic/types.ts index 40b90b012e..69899120af 100644 --- a/test/fixtures/basic/types.ts +++ b/test/fixtures/basic/types.ts @@ -22,41 +22,41 @@ describe('API routes', () => { }) it('works with useAsyncData', () => { - expectTypeOf(useAsyncData('api-hello', () => $fetch('/api/hello')).data).toEqualTypeOf>() - expectTypeOf(useAsyncData('api-hey', () => $fetch('/api/hey')).data).toEqualTypeOf>() - expectTypeOf(useAsyncData('api-hey-with-pick', () => $fetch('/api/hey'), { pick: ['baz'] }).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('api-hello', () => $fetch('/api/hello')).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('api-hey', () => $fetch('/api/hey')).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('api-hey-with-pick', () => $fetch('/api/hey'), { pick: ['baz'] }).data).toEqualTypeOf>() expectTypeOf(useAsyncData('api-other', () => $fetch('/api/other')).data).toEqualTypeOf>() - expectTypeOf(useAsyncData('api-generics', () => $fetch('/test')).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('api-generics', () => $fetch('/test')).data).toEqualTypeOf>() expectTypeOf(useAsyncData('api-error-generics', () => $fetch('/error')).error).toEqualTypeOf>() expectTypeOf(useAsyncData('api-error-generics', () => $fetch('/error')).error).toEqualTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-hello', () => $fetch('/api/hello')).data).toEqualTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-hey', () => $fetch('/api/hey')).data).toEqualTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-hey-with-pick', () => $fetch('/api/hey'), { pick: ['baz'] }).data).toEqualTypeOf>() + expectTypeOf(useLazyAsyncData('lazy-api-hello', () => $fetch('/api/hello')).data).toEqualTypeOf>() + expectTypeOf(useLazyAsyncData('lazy-api-hey', () => $fetch('/api/hey')).data).toEqualTypeOf>() + expectTypeOf(useLazyAsyncData('lazy-api-hey-with-pick', () => $fetch('/api/hey'), { pick: ['baz'] }).data).toEqualTypeOf>() expectTypeOf(useLazyAsyncData('lazy-api-other', () => $fetch('/api/other')).data).toEqualTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-generics', () => $fetch('/test')).data).toEqualTypeOf>() + expectTypeOf(useLazyAsyncData('lazy-api-generics', () => $fetch('/test')).data).toEqualTypeOf>() expectTypeOf(useLazyAsyncData('lazy-error-generics', () => $fetch('/error')).error).toEqualTypeOf>() expectTypeOf(useLazyAsyncData('lazy-error-generics', () => $fetch('/error')).error).toEqualTypeOf>() }) it('works with useFetch', () => { - expectTypeOf(useFetch('/api/hello').data).toEqualTypeOf>() - expectTypeOf(useFetch('/api/hey').data).toEqualTypeOf>() - expectTypeOf(useFetch('/api/hey', { pick: ['baz'] }).data).toEqualTypeOf>() + expectTypeOf(useFetch('/api/hello').data).toEqualTypeOf>() + expectTypeOf(useFetch('/api/hey').data).toEqualTypeOf>() + expectTypeOf(useFetch('/api/hey', { pick: ['baz'] }).data).toEqualTypeOf>() expectTypeOf(useFetch('/api/other').data).toEqualTypeOf>() - expectTypeOf(useFetch('/test').data).toEqualTypeOf>() + expectTypeOf(useFetch('/test').data).toEqualTypeOf>() expectTypeOf(useFetch('/error').error).toEqualTypeOf>() expectTypeOf(useFetch('/error').error).toEqualTypeOf>() - expectTypeOf(useLazyFetch('/api/hello').data).toEqualTypeOf>() - expectTypeOf(useLazyFetch('/api/hey').data).toEqualTypeOf>() - expectTypeOf(useLazyFetch('/api/hey', { pick: ['baz'] }).data).toEqualTypeOf>() + expectTypeOf(useLazyFetch('/api/hello').data).toEqualTypeOf>() + expectTypeOf(useLazyFetch('/api/hey').data).toEqualTypeOf>() + expectTypeOf(useLazyFetch('/api/hey', { pick: ['baz'] }).data).toEqualTypeOf>() expectTypeOf(useLazyFetch('/api/other').data).toEqualTypeOf>() expectTypeOf(useLazyFetch('/api/other').data).toEqualTypeOf>() - expectTypeOf(useLazyFetch('/test').data).toEqualTypeOf>() + expectTypeOf(useLazyFetch('/test').data).toEqualTypeOf>() expectTypeOf(useLazyFetch('/error').error).toEqualTypeOf>() expectTypeOf(useLazyFetch('/error').error).toEqualTypeOf>() @@ -82,7 +82,7 @@ describe('middleware', () => { addRouteMiddleware('example', (to, from) => { expectTypeOf(to).toEqualTypeOf() expectTypeOf(from).toEqualTypeOf() - expectTypeOf(navigateTo).toEqualTypeOf<(to: RouteLocationRaw, options?: NavigateToOptions) => RouteLocationRaw | Promise>() + expectTypeOf(navigateTo).toEqualTypeOf<(to: RouteLocationRaw | null | undefined, options?: NavigateToOptions) => RouteLocationRaw | Promise>() navigateTo('/') abortNavigation() abortNavigation('error string') @@ -157,29 +157,29 @@ describe('composables', () => { expectTypeOf(useCookie('test', { default: () => ref(500) })).toEqualTypeOf>() expectTypeOf(useCookie('test', { default: () => 500 })).toEqualTypeOf>() - expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => ref(500) }).data).toEqualTypeOf>() - expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => 500 }).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => ref(500) }).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => 500 }).data).toEqualTypeOf>() // @ts-expect-error - expectTypeOf(useAsyncData('test', () => Promise.resolve('500'), { default: () => ref(500) }).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('test', () => Promise.resolve('500'), { default: () => ref(500) }).data).toEqualTypeOf>() // @ts-expect-error - expectTypeOf(useAsyncData('test', () => Promise.resolve('500'), { default: () => 500 }).data).toEqualTypeOf>() + expectTypeOf(useAsyncData('test', () => Promise.resolve('500'), { default: () => 500 }).data).toEqualTypeOf>() - expectTypeOf(useFetch('/test', { default: () => ref(500) }).data).toEqualTypeOf>() - expectTypeOf(useFetch('/test', { default: () => 500 }).data).toEqualTypeOf>() + expectTypeOf(useFetch('/test', { default: () => ref(500) }).data).toEqualTypeOf>() + expectTypeOf(useFetch('/test', { default: () => 500 }).data).toEqualTypeOf>() }) it('infer request url string literal from server/api routes', () => { // request can accept dynamic string type const dynamicStringUrl: string = 'https://example.com/api' - expectTypeOf(useFetch(dynamicStringUrl).data).toEqualTypeOf>>() + expectTypeOf(useFetch(dynamicStringUrl).data).toEqualTypeOf>() // request param should infer string literal type / show auto-complete hint base on server routes, ex: '/api/hello' - expectTypeOf(useFetch('/api/hello').data).toEqualTypeOf>() - expectTypeOf(useLazyFetch('/api/hello').data).toEqualTypeOf>() + expectTypeOf(useFetch('/api/hello').data).toEqualTypeOf>() + expectTypeOf(useLazyFetch('/api/hello').data).toEqualTypeOf>() // request can accept string literal and Request object type - expectTypeOf(useFetch('https://example.com/api').data).toEqualTypeOf>>() - expectTypeOf(useFetch(new Request('test')).data).toEqualTypeOf>>() + expectTypeOf(useFetch('https://example.com/api').data).toEqualTypeOf>() + expectTypeOf(useFetch(new Request('test')).data).toEqualTypeOf>() }) it('provides proper type support when using overloads', () => {