diff --git a/test/fixtures/basic/types.ts b/test/fixtures/basic/types.ts index 7e896f81c0..85e5f89ee0 100644 --- a/test/fixtures/basic/types.ts +++ b/test/fixtures/basic/types.ts @@ -4,6 +4,7 @@ import type { Ref } from 'vue' import { NavigationFailure, RouteLocationNormalizedLoaded, RouteLocationRaw, useRouter as vueUseRouter } from 'vue-router' import { defineNuxtConfig } from '~~/../../../packages/nuxt/src' +import type { NavigateToOptions } from '~~/../../../packages/nuxt/dist/app/composables/router' import { isVue3 } from '#app' import { useRouter } from '#imports' @@ -11,58 +12,58 @@ interface TestResponse { message: string } describe('API routes', () => { it('generates types for routes', () => { - expectTypeOf($fetch('/api/hello')).toMatchTypeOf>() - expectTypeOf($fetch('/api/hey')).toMatchTypeOf>() - expectTypeOf($fetch('/api/other')).toMatchTypeOf>() - expectTypeOf($fetch('/test')).toMatchTypeOf>() + expectTypeOf($fetch('/api/hello')).toEqualTypeOf>() + expectTypeOf($fetch('/api/hey')).toEqualTypeOf>() + expectTypeOf($fetch('/api/other')).toEqualTypeOf>() + expectTypeOf($fetch('/test')).toEqualTypeOf>() }) it('works with useAsyncData', () => { - expectTypeOf(useAsyncData('api-hello', () => $fetch('/api/hello')).data).toMatchTypeOf>() - expectTypeOf(useAsyncData('api-hey', () => $fetch('/api/hey')).data).toMatchTypeOf>() - expectTypeOf(useAsyncData('api-hey-with-pick', () => $fetch('/api/hey'), { pick: ['baz'] }).data).toMatchTypeOf>() - expectTypeOf(useAsyncData('api-other', () => $fetch('/api/other')).data).toMatchTypeOf>() - expectTypeOf(useAsyncData('api-generics', () => $fetch('/test')).data).toMatchTypeOf>() + 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-error-generics', () => $fetch('/error')).error).toMatchTypeOf>() - expectTypeOf(useAsyncData('api-error-generics', () => $fetch('/error')).error).toMatchTypeOf>() + 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).toMatchTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-hey', () => $fetch('/api/hey')).data).toMatchTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-hey-with-pick', () => $fetch('/api/hey'), { pick: ['baz'] }).data).toMatchTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-other', () => $fetch('/api/other')).data).toMatchTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-api-generics', () => $fetch('/test')).data).toMatchTypeOf>() + 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-error-generics', () => $fetch('/error')).error).toMatchTypeOf>() - expectTypeOf(useLazyAsyncData('lazy-error-generics', () => $fetch('/error')).error).toMatchTypeOf>() + 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).toMatchTypeOf>() - expectTypeOf(useFetch('/api/hey').data).toMatchTypeOf>() - expectTypeOf(useFetch('/api/hey', { pick: ['baz'] }).data).toMatchTypeOf>() - expectTypeOf(useFetch('/api/other').data).toMatchTypeOf>() - expectTypeOf(useFetch('/test').data).toMatchTypeOf>() + 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('/error').error).toMatchTypeOf>() - expectTypeOf(useFetch('/error').error).toMatchTypeOf>() + expectTypeOf(useFetch('/error').error).toEqualTypeOf>() + expectTypeOf(useFetch('/error').error).toEqualTypeOf>() - expectTypeOf(useLazyFetch('/api/hello').data).toMatchTypeOf>() - expectTypeOf(useLazyFetch('/api/hey').data).toMatchTypeOf>() - expectTypeOf(useLazyFetch('/api/hey', { pick: ['baz'] }).data).toMatchTypeOf>() - expectTypeOf(useLazyFetch('/api/other').data).toMatchTypeOf>() - expectTypeOf(useLazyFetch('/api/other').data).toMatchTypeOf>() - expectTypeOf(useLazyFetch('/test').data).toMatchTypeOf>() + 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('/error').error).toMatchTypeOf>() - expectTypeOf(useLazyFetch('/error').error).toMatchTypeOf>() + expectTypeOf(useLazyFetch('/error').error).toEqualTypeOf>() + expectTypeOf(useLazyFetch('/error').error).toEqualTypeOf>() }) }) describe('aliases', () => { it('allows importing from path aliases', () => { - expectTypeOf(useRouter).toMatchTypeOf() - expectTypeOf(isVue3).toMatchTypeOf() + expectTypeOf(useRouter).toEqualTypeOf() + expectTypeOf(isVue3).toEqualTypeOf() }) }) @@ -76,9 +77,9 @@ describe('middleware', () => { }) it('handles adding middleware', () => { addRouteMiddleware('example', (to, from) => { - expectTypeOf(to).toMatchTypeOf() - expectTypeOf(from).toMatchTypeOf() - expectTypeOf(navigateTo).toMatchTypeOf<(to: RouteLocationRaw) => RouteLocationRaw | Promise>() + expectTypeOf(to).toEqualTypeOf() + expectTypeOf(from).toEqualTypeOf() + expectTypeOf(navigateTo).toEqualTypeOf<(to: RouteLocationRaw, options?: NavigateToOptions) => RouteLocationRaw | Promise>() navigateTo('/') abortNavigation() abortNavigation('error string') @@ -110,57 +111,57 @@ describe('modules', () => { describe('runtimeConfig', () => { it('generated runtimeConfig types', () => { const runtimeConfig = useRuntimeConfig() - expectTypeOf(runtimeConfig.testConfig).toMatchTypeOf() - expectTypeOf(runtimeConfig.privateConfig).toMatchTypeOf() - expectTypeOf(runtimeConfig.unknown).toMatchTypeOf() + expectTypeOf(runtimeConfig.testConfig).toEqualTypeOf() + expectTypeOf(runtimeConfig.privateConfig).toEqualTypeOf() + expectTypeOf(runtimeConfig.unknown).toEqualTypeOf() }) }) describe('composables', () => { it('allows providing default refs', () => { - expectTypeOf(useState('test', () => ref('hello'))).toMatchTypeOf>() - expectTypeOf(useState('test', () => 'hello')).toMatchTypeOf>() + expectTypeOf(useState('test', () => ref('hello'))).toEqualTypeOf>() + expectTypeOf(useState('test', () => 'hello')).toEqualTypeOf>() - expectTypeOf(useCookie('test', { default: () => ref(500) })).toMatchTypeOf>() - expectTypeOf(useCookie('test', { default: () => 500 })).toMatchTypeOf>() + expectTypeOf(useCookie('test', { default: () => ref(500) })).toEqualTypeOf>() + expectTypeOf(useCookie('test', { default: () => 500 })).toEqualTypeOf>() - expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => ref(500) }).data).toMatchTypeOf>() - expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => 500 }).data).toMatchTypeOf>() + 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).toMatchTypeOf>() + expectTypeOf(useAsyncData('test', () => Promise.resolve('500'), { default: () => ref(500) }).data).toEqualTypeOf>() // @ts-expect-error - expectTypeOf(useAsyncData('test', () => Promise.resolve('500'), { default: () => 500 }).data).toMatchTypeOf>() + expectTypeOf(useAsyncData('test', () => Promise.resolve('500'), { default: () => 500 }).data).toEqualTypeOf>() - expectTypeOf(useFetch('/test', { default: () => ref(500) }).data).toMatchTypeOf>() - expectTypeOf(useFetch('/test', { default: () => 500 }).data).toMatchTypeOf>() + 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).toMatchTypeOf>>() + const dynamicStringUrl: string = 'https://example.com/api' + 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).toMatchTypeOf>() - expectTypeOf(useLazyFetch('/api/hello').data).toMatchTypeOf>() + 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).toMatchTypeOf>>() - expectTypeOf(useFetch(new Request('test')).data).toMatchTypeOf>>() + expectTypeOf(useFetch('https://example.com/api').data).toEqualTypeOf>>() + expectTypeOf(useFetch(new Request('test')).data).toEqualTypeOf>>() }) it('provides proper type support when using overloads', () => { - expectTypeOf(useState('test')).toMatchTypeOf(useState()) - expectTypeOf(useState('test', () => ({ foo: Math.random() }))).toMatchTypeOf(useState(() => ({ foo: Math.random() }))) + expectTypeOf(useState('test')).toEqualTypeOf(useState()) + expectTypeOf(useState('test', () => ({ foo: Math.random() }))).toEqualTypeOf(useState(() => ({ foo: Math.random() }))) expectTypeOf(useAsyncData('test', () => Promise.resolve({ foo: Math.random() }))) - .toMatchTypeOf(useAsyncData(() => Promise.resolve({ foo: Math.random() }))) + .toEqualTypeOf(useAsyncData(() => Promise.resolve({ foo: Math.random() }))) expectTypeOf(useAsyncData('test', () => Promise.resolve({ foo: Math.random() }), { transform: data => data.foo })) - .toMatchTypeOf(useAsyncData(() => Promise.resolve({ foo: Math.random() }), { transform: data => data.foo })) + .toEqualTypeOf(useAsyncData(() => Promise.resolve({ foo: Math.random() }), { transform: data => data.foo })) expectTypeOf(useLazyAsyncData('test', () => Promise.resolve({ foo: Math.random() }))) - .toMatchTypeOf(useLazyAsyncData(() => Promise.resolve({ foo: Math.random() }))) + .toEqualTypeOf(useLazyAsyncData(() => Promise.resolve({ foo: Math.random() }))) expectTypeOf(useLazyAsyncData('test', () => Promise.resolve({ foo: Math.random() }), { transform: data => data.foo })) - .toMatchTypeOf(useLazyAsyncData(() => Promise.resolve({ foo: Math.random() }), { transform: data => data.foo })) + .toEqualTypeOf(useLazyAsyncData(() => Promise.resolve({ foo: Math.random() }), { transform: data => data.foo })) }) })