]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: further tweak createElement type inference
authorEvan You <yyx990803@gmail.com>
Sat, 13 Oct 2018 02:07:08 +0000 (22:07 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 13 Oct 2018 02:07:08 +0000 (22:07 -0400)
packages/core/src/h.ts

index c461017d1a9356e20ce86ebc3efdf1374195caa9..c07e11f484f259d328f83aede575ce02e6d5e726 100644 (file)
@@ -54,53 +54,51 @@ type OptionsComponent<P> =
   | (ComponentOptions<P> & { template: string })
   | (ComponentOptions<P> & { render: Function })
 
+// TODO improve return type with props information
 interface createElement extends VNodeFactories {
   // element
+  (tag: string, children?: RawChildrenType): VNode
   (
     tag: string,
     // TODO support native element properties
     data?: VNodeData & Differ | null,
     children?: RawChildrenType | RawSlots
   ): VNode
-  (tag: string, children?: RawChildrenType): VNode
   // fragment
+  (tag: typeof Fragment, children?: RawChildrenType): VNode
   (
     tag: typeof Fragment,
     data?: ({ key?: Key } & Differ) | null,
     children?: RawChildrenType | RawSlots
   ): VNode
-  (tag: typeof Fragment, children?: RawChildrenType): VNode
   // portal
+  (tag: typeof Portal, children?: RawChildrenType): VNode
   (
     tag: typeof Portal,
     data?: ({ target: any } & BuiltInProps & Differ) | null,
     children?: RawChildrenType | RawSlots
   ): VNode
-  (tag: typeof Portal, children?: RawChildrenType): VNode
   // object
+  <P>(tag: OptionsComponent<P>, children?: RawChildrenType): VNode
   <P>(
     tag: OptionsComponent<P>,
     data?: (P & BuiltInProps & Differ) | null,
     children?: RawChildrenType | RawSlots
   ): VNode
-  <P>(tag: OptionsComponent<P>, children?: RawChildrenType): VNode
   // functional
+  <P>(tag: FunctionalComponent<P>, children?: RawChildrenType): VNode
   <P>(
     tag: FunctionalComponent<P>,
     data?: (P & BuiltInProps & Differ) | null,
     children?: RawChildrenType | RawSlots
   ): VNode
-  <P>(tag: FunctionalComponent<P>, children?: RawChildrenType): VNode
   // class
-  <P, T extends ComponentInstance<P>>(
-    tag: new () => T & { $props: P },
+  <P>(tag: new () => ComponentInstance<P>, children?: RawChildrenType): VNode
+  <P>(
+    tag: new () => ComponentInstance<P>,
     data?: (P & BuiltInProps & Differ) | null,
     children?: RawChildrenType | RawSlots
   ): VNode
-  <P, T extends ComponentInstance<P>>(
-    tag: new () => T & { $props: P },
-    children?: RawChildrenType
-  ): VNode
 }
 
 export const h = ((tag: ElementType, data?: any, children?: any): VNode => {