types: further tweak createElement type inference

This commit is contained in:
Evan You 2018-10-12 22:07:08 -04:00
parent 5257b366fd
commit 2599580bca

View File

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