Skip to content

Commit

Permalink
fix(types): sync vue type augmentations with Vue 2.7 (#19526)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Roe <daniel@roe.dev>
  • Loading branch information
rchl and danielroe committed Mar 16, 2023
1 parent 8e0aba0 commit ce1df2f
Showing 1 changed file with 88 additions and 14 deletions.
102 changes: 88 additions & 14 deletions packages/types/app/vue.d.ts
Expand Up @@ -5,8 +5,9 @@
import type Vue from 'vue'
import type { MetaInfo } from 'vue-meta'
import type { Route } from 'vue-router'
import type { RecordPropsDefinition, PropsDefinition, ComponentOptions } from 'vue/types/options'
import type { CombinedVueInstance, ExtendedVue } from 'vue/types/vue'
import type { RecordPropsDefinition, ComponentOptions } from 'vue/types/options'
import type { ComponentOptionsMixin } from 'vue/types/v3-component-options'
import type { CombinedVueInstance } from 'vue/types/vue'
import type { NuxtRuntimeConfig } from '../config/runtime'
import type { Context, Middleware, Transition, NuxtApp } from './index'

Expand All @@ -26,6 +27,9 @@ declare module 'vue/types/options' {
Computed = DefaultComputed,
PropsDef = PropsDefinition<DefaultProps>,
Props = DefaultProps,
RawBindings = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
/* eslint-enable no-unused-vars,@typescript-eslint/no-unused-vars */
AsyncData = DefaultAsyncData<V>
> {
Expand Down Expand Up @@ -60,7 +64,10 @@ type ThisTypedComponentOptionsWithArrayPropsAndAsyncData<
Methods,
Computed,
PropNames extends string,
AsyncData
SetupBindings,
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V> = DefaultAsyncData<V>
> = object &
ComponentOptions<
V,
Expand All @@ -69,15 +76,21 @@ type ThisTypedComponentOptionsWithArrayPropsAndAsyncData<
Computed,
PropNames[],
Record<PropNames, any>,
DataDef<AsyncData, PropNames, V>
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends,
AsyncData
> &
ThisType<
CombinedVueInstance<
V,
Merged<Data, Awaited<AsyncData>>,
Merged<Data, Awaited<ReturnType<AsyncData>>>,
Methods,
Computed,
Readonly<Record<PropNames, any>>
Readonly<Record<PropNames, any>>,
SetupBindings,
Mixin,
Extends
>
>
export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData<
Expand All @@ -86,7 +99,10 @@ export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData<
Methods,
Computed,
Props,
AsyncData
SetupBindings,
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V>
> = object &
ComponentOptions<
V,
Expand All @@ -95,12 +111,25 @@ export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData<
Computed,
RecordPropsDefinition<Props>,
Props,
DataDef<AsyncData, Props, V>
> &
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends,
AsyncData
> &
ThisType<
CombinedVueInstance<V, Merged<Data, Awaited<AsyncData>>, Methods, Computed, Readonly<Props>>
CombinedVueInstance<
V,
Merged<Data, Awaited<ReturnType<AsyncData>>>,
Methods,
Computed,
Readonly<Props>,
SetupBindings,
Mixin,
Extends
>
>


declare module 'vue/types/vue' {
interface Vue {
$config: NuxtRuntimeConfig
Expand All @@ -113,25 +142,70 @@ declare module 'vue/types/vue' {
}
}
interface VueConstructor<V extends Vue> {
extend<Data, Methods, Computed, PropNames extends string, AsyncData>(
/** extend with array props */
extend<
Data,
Methods,
Computed,
PropNames extends string = never,
SetupBindings = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V> = DefaultAsyncData<V>
>(
options?: ThisTypedComponentOptionsWithArrayPropsAndAsyncData<
V,
Data,
Methods,
Computed,
PropNames,
SetupBindings,
Mixin,
Extends,
AsyncData
>
): ExtendedVue<V, Data, Methods, Computed, Record<PropNames, any>>
extend<Data, Methods, Computed, Props, AsyncData>(
): ExtendedVue<
V,
Data,
Methods,
Computed,
Record<PropNames, any>,
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends
>

/** extend with object props */
extend<
Data,
Methods,
Computed,
Props,
SetupBindings = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V> = DefaultAsyncData<V>
>(
options?: ThisTypedComponentOptionsWithRecordPropsAndAsyncData<
V,
Data,
Methods,
Computed,
Props,
SetupBindings,
Mixin,
Extends,
AsyncData
>
): ExtendedVue<V, Data, Methods, Computed, Props>
): ExtendedVue<
V,
Data,
Methods,
Computed,
Props,
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends
>
}
}

0 comments on commit ce1df2f

Please sign in to comment.