Skip to content

Commit

Permalink
fix(nuxt): do not override inferred type of <NuxtPage> (#18495)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 25, 2023
1 parent 6e7ebc4 commit 9751c9d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
11 changes: 2 additions & 9 deletions packages/nuxt/src/pages/runtime/page.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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] : [])
Expand Down
7 changes: 0 additions & 7 deletions packages/nuxt/src/pages/runtime/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/types.d.ts
Original file line number Diff line number Diff line change
@@ -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']
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/basic/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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>>()
Expand Down

0 comments on commit 9751c9d

Please sign in to comment.