From a2cb49fd20502899465f6e7dae13438326cd440b Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Wed, 8 Mar 2023 13:21:39 +0100 Subject: [PATCH 1/5] fix(types): non-matching declaration of 'ComponentOptions' --- packages/types/app/vue.d.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/types/app/vue.d.ts b/packages/types/app/vue.d.ts index 655a7bf7f42e..23a1acab26b0 100644 --- a/packages/types/app/vue.d.ts +++ b/packages/types/app/vue.d.ts @@ -18,19 +18,8 @@ type DefaultComputed = { [key: string]: any } type DefaultAsyncData = ((this: V, context: Context) => Promise | object | void) declare module 'vue/types/options' { - interface ComponentOptions< - V extends Vue, - /* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */ - Data = DefaultData, - Methods = DefaultMethods, - Computed = DefaultComputed, - PropsDef = PropsDefinition, - Props = DefaultProps, - /* eslint-enable no-unused-vars,@typescript-eslint/no-unused-vars */ - AsyncData = DefaultAsyncData - > { - // eslint-disable-next-line @typescript-eslint/ban-types - asyncData?: AsyncData + interface ComponentOptions { + asyncData?: DefaultAsyncData fetch?(ctx: Context): Promise | void fetchKey?: string | ((getKey: (id: string) => number) => string) fetchDelay?: number From f7c62539daebcf194f0340786f98c368d2cffa78 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Wed, 8 Mar 2023 13:30:59 +0100 Subject: [PATCH 2/5] cleanup --- packages/types/app/vue.d.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/types/app/vue.d.ts b/packages/types/app/vue.d.ts index 23a1acab26b0..52c7353fc009 100644 --- a/packages/types/app/vue.d.ts +++ b/packages/types/app/vue.d.ts @@ -5,21 +5,16 @@ 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 { RecordPropsDefinition, ComponentOptions } from 'vue/types/options' import type { CombinedVueInstance, ExtendedVue } from 'vue/types/vue' import type { NuxtRuntimeConfig } from '../config/runtime' import type { Context, Middleware, Transition, NuxtApp } from './index' -// https://github.com/vuejs/vue/blob/dev/types/options.d.ts#L63-L66 -type DefaultData = object | ((this: V) => object) -type DefaultProps = Record -type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any } -type DefaultComputed = { [key: string]: any } -type DefaultAsyncData = ((this: V, context: Context) => Promise | object | void) +type AsyncData = ((this: V, context: Context) => Promise | object | void) declare module 'vue/types/options' { interface ComponentOptions { - asyncData?: DefaultAsyncData + asyncData?: AsyncData fetch?(ctx: Context): Promise | void fetchKey?: string | ((getKey: (id: string) => number) => string) fetchDelay?: number From ae3f36d87bcb7e22415781defff60c511bb439df Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 15 Mar 2023 13:44:59 +0000 Subject: [PATCH 3/5] fix: sync with vue 2.7 generic types --- packages/types/app/vue.d.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/types/app/vue.d.ts b/packages/types/app/vue.d.ts index 52c7353fc009..ac7ae5670524 100644 --- a/packages/types/app/vue.d.ts +++ b/packages/types/app/vue.d.ts @@ -6,15 +6,35 @@ import type Vue from 'vue' import type { MetaInfo } from 'vue-meta' import type { Route } from 'vue-router' import type { RecordPropsDefinition, ComponentOptions } from 'vue/types/options' -import type { CombinedVueInstance, ExtendedVue } from 'vue/types/vue' +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' -type AsyncData = ((this: V, context: Context) => Promise | object | void) +// https://github.com/vuejs/vue/blob/dev/types/options.d.ts#L63-L66 +type DefaultData = object | ((this: V) => object) +type DefaultProps = Record +type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any } +type DefaultComputed = { [key: string]: any } +type DefaultAsyncData = ((this: V, context: Context) => Promise | object | void) declare module 'vue/types/options' { - interface ComponentOptions { - asyncData?: AsyncData + interface ComponentOptions< + V extends Vue, + /* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */ + Data = DefaultData, + Methods = DefaultMethods, + Computed = DefaultComputed, + PropsDef = PropsDefinition, + Props = DefaultProps, + RawBindings = {}, + Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, + Extends extends ComponentOptionsMixin = ComponentOptionsMixin, + /* eslint-enable no-unused-vars,@typescript-eslint/no-unused-vars */ + AsyncData = DefaultAsyncData + > { + // eslint-disable-next-line @typescript-eslint/ban-types + asyncData?: AsyncData fetch?(ctx: Context): Promise | void fetchKey?: string | ((getKey: (id: string) => number) => string) fetchDelay?: number From 0d9695304acca9326002c0ad6ba7c659ed67f6be Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 16 Mar 2023 14:44:09 +0000 Subject: [PATCH 4/5] fix: handle new Vue 2.7 extend generics --- packages/types/app/vue.d.ts | 94 ++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/packages/types/app/vue.d.ts b/packages/types/app/vue.d.ts index ac7ae5670524..6ed3f4db9cbc 100644 --- a/packages/types/app/vue.d.ts +++ b/packages/types/app/vue.d.ts @@ -64,7 +64,10 @@ type ThisTypedComponentOptionsWithArrayPropsAndAsyncData< Methods, Computed, PropNames extends string, - AsyncData + SetupBindings, + Mixin extends ComponentOptionsMixin, + Extends extends ComponentOptionsMixin, + AsyncData extends DefaultAsyncData = DefaultAsyncData > = object & ComponentOptions< V, @@ -73,15 +76,21 @@ type ThisTypedComponentOptionsWithArrayPropsAndAsyncData< Computed, PropNames[], Record, - DataDef + SetupBindings, + Mixin, + Extends, + AsyncData > & ThisType< CombinedVueInstance< V, - Merged>, + Merged>>, Methods, Computed, - Readonly> + Readonly>, + SetupBindings, + Mixin, + Extends > > export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData< @@ -90,7 +99,10 @@ export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData< Methods, Computed, Props, - AsyncData + SetupBindings, + Mixin extends ComponentOptionsMixin, + Extends extends ComponentOptionsMixin, + AsyncData extends DefaultAsyncData > = object & ComponentOptions< V, @@ -99,12 +111,25 @@ export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData< Computed, RecordPropsDefinition, Props, - DataDef -> & + SetupBindings, + Mixin, + Extends, + AsyncData + > & ThisType< - CombinedVueInstance>, Methods, Computed, Readonly> + CombinedVueInstance< + V, + Merged>>, + Methods, + Computed, + Readonly, + SetupBindings, + Mixin, + Extends + > > + declare module 'vue/types/vue' { interface Vue { $config: NuxtRuntimeConfig @@ -117,25 +142,70 @@ declare module 'vue/types/vue' { } } interface VueConstructor { - extend( + /** extend with array props */ + extend< + Data, + Methods, + Computed, + PropNames extends string = never, + SetupBindings = {}, + Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, + Extends extends ComponentOptionsMixin = ComponentOptionsMixin, + AsyncData extends DefaultAsyncData = DefaultAsyncData + >( options?: ThisTypedComponentOptionsWithArrayPropsAndAsyncData< V, Data, Methods, Computed, PropNames, + SetupBindings, + Mixin, + Extends, AsyncData > - ): ExtendedVue> - extend( + ): ExtendedVue< + V, + Data, + Methods, + Computed, + Record, + SetupBindings, + Mixin, + Extends + > + + /** extend with object props */ + extend< + Data, + Methods, + Computed, + Props, + SetupBindings = {}, + Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, + Extends extends ComponentOptionsMixin = ComponentOptionsMixin, + AsyncData extends DefaultAsyncData = DefaultAsyncData + >( options?: ThisTypedComponentOptionsWithRecordPropsAndAsyncData< V, Data, Methods, Computed, Props, + SetupBindings, + Mixin, + Extends, AsyncData > - ): ExtendedVue + ): ExtendedVue< + V, + Data, + Methods, + Computed, + Props, + SetupBindings, + Mixin, + Extends + > } } From 30565fc5b7218567d40c3b400383df598b8d44a8 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 16 Mar 2023 14:59:53 +0000 Subject: [PATCH 5/5] fix: expose asyncData to template as well --- packages/types/app/vue.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/types/app/vue.d.ts b/packages/types/app/vue.d.ts index 6ed3f4db9cbc..596909d05cd1 100644 --- a/packages/types/app/vue.d.ts +++ b/packages/types/app/vue.d.ts @@ -76,7 +76,7 @@ type ThisTypedComponentOptionsWithArrayPropsAndAsyncData< Computed, PropNames[], Record, - SetupBindings, + Merged>>, Mixin, Extends, AsyncData @@ -111,7 +111,7 @@ export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData< Computed, RecordPropsDefinition, Props, - SetupBindings, + Merged>>, Mixin, Extends, AsyncData @@ -170,7 +170,7 @@ declare module 'vue/types/vue' { Methods, Computed, Record, - SetupBindings, + Merged>>, Mixin, Extends > @@ -203,7 +203,7 @@ declare module 'vue/types/vue' { Methods, Computed, Props, - SetupBindings, + Merged>>, Mixin, Extends >