Browse Source

fix(types): fix app.component() typing with inline defineComponent

close #10843
Evan You 2 years ago
parent
commit
908f70adc0

+ 14 - 0
packages/dts-test/defineComponent.test-d.tsx

@@ -1959,3 +1959,17 @@ declare const ErrorMessage: {
     }
   })
 ;<ErrorMessage name="password" class="error" />
+
+// #10843
+createApp({}).component(
+  'SomeComponent',
+  defineComponent({
+    props: {
+      title: String,
+    },
+    setup(props) {
+      expectType<string | undefined>(props.title)
+      return {}
+    },
+  }),
+)

+ 4 - 1
packages/runtime-core/src/apiCreateApp.ts

@@ -42,7 +42,10 @@ export interface App<HostElement = any> {
 
   mixin(mixin: ComponentOptions): this
   component(name: string): Component | undefined
-  component(name: string, component: Component | DefineComponent): this
+  component<T extends Component | DefineComponent>(
+    name: string,
+    component: T,
+  ): this
   directive<T = any, V = any>(name: string): Directive<T, V> | undefined
   directive<T = any, V = any>(name: string, directive: Directive<T, V>): this
   mount(