Selaa lähdekoodia

fix(types): global component registration type compat w/ defineComponent

fix #12622
Evan You 3 vuotta sitten
vanhempi
commit
26ff4bc0ed
2 muutettua tiedostoa jossa 12 lisäystä ja 6 poistoa
  1. 7 6
      types/test/v3/define-component-test.tsx
  2. 5 0
      types/vue.d.ts

+ 7 - 6
types/test/v3/define-component-test.tsx

@@ -1,3 +1,4 @@
+import Vue, { VueConstructor } from '../../index'
 import {
   Component,
   defineComponent,
@@ -8,12 +9,12 @@ import {
 } from '../../index'
 import { describe, test, expectType, expectError, IsUnion } from '../utils'
 
-defineComponent({
-  props: {
-    foo: Number
-  },
-  render() {
-    this.foo
+describe('compat with v2 APIs', () => {
+  const comp = defineComponent({})
+
+  Vue.component('foo', comp)
+  function install(app: VueConstructor) {
+    app.component('foo', comp)
   }
 })
 

+ 5 - 0
types/vue.d.ts

@@ -14,6 +14,7 @@ import {
 } from './options'
 import { VNode, VNodeData, VNodeChildren, NormalizedScopedSlot } from './vnode'
 import { PluginFunction, PluginObject } from './plugin'
+import { DefineComponent } from './v3-define-component'
 
 export interface CreateElement {
   (
@@ -313,6 +314,10 @@ export interface VueConstructor<V extends Vue = Vue> {
     id: string,
     definition?: ComponentOptions<V>
   ): ExtendedVue<V, {}, {}, {}, {}, {}>
+  component<T extends DefineComponent<any, any, any, any, any, any, any, any>>(
+    id: string,
+    definition?: T
+  ): T
 
   use<T>(
     plugin: PluginObject<T> | PluginFunction<T>,