]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(types): expose ComponentCustomOptions for declaring custom options
authorEvan You <yyx990803@gmail.com>
Fri, 17 Apr 2020 13:41:36 +0000 (09:41 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 17 Apr 2020 13:41:36 +0000 (09:41 -0400)
packages/runtime-core/src/componentOptions.ts
packages/runtime-core/src/index.ts
test-dts/componentTypeExtensions.test-d.ts [moved from test-dts/componentCustomProperties.test-d.ts with 71% similarity]

index 39087e8c311aed36a3f5a4dd10fc4dd693cce10c..40c861cbdcb9842c3635406f677320ccdff6e7fb 100644 (file)
@@ -51,6 +51,24 @@ import { Directive } from './directives'
 import { ComponentPublicInstance } from './componentProxy'
 import { warn } from './warning'
 
+/**
+ * Interface for declaring custom options.
+ *
+ * @example
+ * ```ts
+ * declare module '@vue/runtime-core' {
+ *   interface ComponentCustomOptions {
+ *     beforeRouteUpdate?(
+ *       to: Route,
+ *       from: Route,
+ *       next: () => void
+ *     ): void
+ *   }
+ * }
+ * ```
+ */
+export interface ComponentCustomOptions {}
+
 export interface ComponentOptionsBase<
   Props,
   RawBindings,
@@ -59,7 +77,10 @@ export interface ComponentOptionsBase<
   M extends MethodOptions,
   E extends EmitsOptions,
   EE extends string = string
-> extends LegacyOptions<Props, D, C, M>, SFCInternalOptions {
+>
+  extends LegacyOptions<Props, D, C, M>,
+    SFCInternalOptions,
+    ComponentCustomOptions {
   setup?: (
     this: void,
     props: Props,
index f4273cc37c0581f949458cec29c16af8252b9409..316e1c7df641b262d20854336e583b55a22ee97e 100644 (file)
@@ -189,8 +189,9 @@ export {
 export {
   ComponentOptions,
   ComponentOptionsWithoutProps,
-  ComponentOptionsWithObjectProps as ComponentOptionsWithProps,
-  ComponentOptionsWithArrayProps
+  ComponentOptionsWithObjectProps,
+  ComponentOptionsWithArrayProps,
+  ComponentCustomOptions
 } from './componentOptions'
 export {
   ComponentPublicInstance,
similarity index 71%
rename from test-dts/componentCustomProperties.test-d.ts
rename to test-dts/componentTypeExtensions.test-d.ts
index 60267c6b4c2c8c3f2cc1cc7210f1771107fcd876..5066f0b97178184dc868b56944d096276435f839 100644 (file)
@@ -1,7 +1,11 @@
-import { expectError } from 'tsd'
+import { expectError, expectType } from 'tsd'
 import { defineComponent } from './index'
 
 declare module '@vue/runtime-core' {
+  interface ComponentCustomOptions {
+    test?(n: number): void
+  }
+
   interface ComponentCustomProperties {
     state: 'stopped' | 'running'
   }
@@ -9,6 +13,11 @@ declare module '@vue/runtime-core' {
 
 export const Custom = defineComponent({
   data: () => ({ counter: 0 }),
+
+  test(n) {
+    expectType<number>(n)
+  },
+
   methods: {
     aMethod() {
       expectError(this.notExisting)