From 9751c9dab7423d6df8046e68660bcc2615807b87 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 25 Jan 2023 00:44:59 -0800 Subject: [PATCH] fix(nuxt): do not override inferred type of `` (#18495) --- packages/nuxt/src/pages/runtime/page.ts | 11 ++--------- packages/nuxt/src/pages/runtime/plugins/router.ts | 7 ------- packages/nuxt/types.d.ts | 2 +- test/fixtures/basic/types.ts | 7 +++++++ 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/nuxt/src/pages/runtime/page.ts b/packages/nuxt/src/pages/runtime/page.ts index 4d466bf8ea..432b6e6811 100644 --- a/packages/nuxt/src/pages/runtime/page.ts +++ b/packages/nuxt/src/pages/runtime/page.ts @@ -1,5 +1,5 @@ import { computed, defineComponent, h, provide, reactive, onMounted, nextTick, Suspense, Transition } from 'vue' -import type { DefineComponent, VNode, KeepAliveProps, TransitionProps } from 'vue' +import type { VNode, KeepAliveProps, TransitionProps } from 'vue' import { RouterView } from 'vue-router' import { defu } from 'defu' import type { RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteLocation } from 'vue-router' @@ -62,14 +62,7 @@ export default defineComponent({ }) } } -}) as DefineComponent<{ - name?: string - transition?: boolean | TransitionProps - keepalive?: boolean | KeepAliveProps - route?: RouteLocationNormalized - pageKey?: string | ((route: RouteLocationNormalizedLoaded) => string) - [key: string]: any -}> +}) function _toArray (val: any) { return Array.isArray(val) ? val : (val ? [val] : []) diff --git a/packages/nuxt/src/pages/runtime/plugins/router.ts b/packages/nuxt/src/pages/runtime/plugins/router.ts index f47cbdbf43..f52edcdf6f 100644 --- a/packages/nuxt/src/pages/runtime/plugins/router.ts +++ b/packages/nuxt/src/pages/runtime/plugins/router.ts @@ -11,7 +11,6 @@ import { } from 'vue-router' import { createError } from 'h3' import { withoutBase, isEqual } from 'ufo' -import type NuxtPage from '../page' import { callWithNuxt, defineNuxtPlugin, useRuntimeConfig, showError, clearError, navigateTo, useError, useState, useRequestEvent } from '#app' // @ts-ignore import _routes from '#build/routes' @@ -20,12 +19,6 @@ import routerOptions from '#build/router.options' // @ts-ignore import { globalMiddleware, namedMiddleware } from '#build/middleware' -declare module '@vue/runtime-core' { - export interface GlobalComponents { - NuxtPage: typeof NuxtPage - } -} - // https://github.com/vuejs/router/blob/4a0cc8b9c1e642cdf47cc007fa5bbebde70afc66/packages/router/src/history/html5.ts#L37 function createCurrentLocation ( base: string, diff --git a/packages/nuxt/types.d.ts b/packages/nuxt/types.d.ts index a6b548793e..408597d258 100644 --- a/packages/nuxt/types.d.ts +++ b/packages/nuxt/types.d.ts @@ -1,7 +1,7 @@ /// export * from './dist/index' -import type { Schema, SchemaDefinition } from '@nuxt/schema' +import type { SchemaDefinition } from '@nuxt/schema' declare global { const defineNuxtConfig: typeof import('nuxt/config')['defineNuxtConfig'] diff --git a/test/fixtures/basic/types.ts b/test/fixtures/basic/types.ts index e1772e7623..21bf9fe575 100644 --- a/test/fixtures/basic/types.ts +++ b/test/fixtures/basic/types.ts @@ -6,6 +6,7 @@ import type { AppConfig } from '@nuxt/schema' import type { FetchError } from 'ofetch' import type { NavigationFailure, RouteLocationNormalizedLoaded, RouteLocationRaw, useRouter as vueUseRouter } from 'vue-router' import { callWithNuxt, isVue3 } from '#app' +import NuxtPage from '~~/../../../packages/nuxt/src/pages/runtime/page' import type { NavigateToOptions } from '~~/../../../packages/nuxt/dist/app/composables/router' import { defineNuxtConfig } from '~~/../../../packages/nuxt/config' import { useRouter } from '#imports' @@ -155,6 +156,12 @@ describe('head', () => { }) }) +describe('components', () => { + it('includes types for NuxtPage', () => { + expectTypeOf(NuxtPage).not.toBeAny() + }) +}) + describe('composables', () => { it('allows providing default refs', () => { expectTypeOf(useState('test', () => ref('hello'))).toEqualTypeOf>()