Răsfoiți Sursa

fix(types): fix type inference when using components option

Evan You 3 ani în urmă
părinte
comite
1d5a411c1e
2 a modificat fișierele cu 26 adăugiri și 3 ștergeri
  1. 3 3
      types/options.d.ts
  2. 23 0
      types/test/v3/define-component-test.tsx

+ 3 - 3
types/options.d.ts

@@ -20,7 +20,7 @@ export type Component<
   | typeof Vue
   | FunctionalComponentOptions<Props>
   | ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
-  | DefineComponent<any, any, any, any, any>
+  | DefineComponent<any, any, any, any, any, any, any, any, any, any, any>
 
 type EsModule<T> = T | { default: T }
 
@@ -201,9 +201,9 @@ export interface ComponentOptions<
   directives?: { [key: string]: DirectiveFunction | DirectiveOptions }
   components?: {
     [key: string]:
-      | Component<any, any, any, any>
+      | {}
+      | Component<any, any, any, any, any>
       | AsyncComponent<any, any, any, any>
-      | DefineComponent<any, any, any, any, any, any, any, any, any, any>
   }
   transitions?: { [key: string]: object }
   filters?: { [key: string]: Function }

+ 23 - 0
types/test/v3/define-component-test.tsx

@@ -1115,3 +1115,26 @@ describe('functional w/ object props', () => {
   // @ts-expect-error
   ;<Foo bar={123} />
 })
+
+// #12628
+defineComponent({
+  components: {
+    App: defineComponent({})
+  },
+  data() {
+    return {}
+  },
+  provide(): any {
+    return {
+      fetchData: this.fetchData
+    }
+  },
+  created() {
+    this.fetchData()
+  },
+  methods: {
+    fetchData() {
+      throw new Error('Not implemented.')
+    }
+  }
+})