fix(nuxt): do not override inferred type of <NuxtPage> (#18495)

This commit is contained in:
Daniel Roe 2023-01-25 00:44:59 -08:00 committed by GitHub
parent 6e7ebc4484
commit 9751c9dab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 17 deletions

View File

@ -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] : [])

View File

@ -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,

View File

@ -1,7 +1,7 @@
/// <reference types="nitropack" />
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']

View File

@ -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<Ref<string>>()