export interface ComponentClass extends ComponentClassOptions {
options?: ComponentOptions
- new <P extends object = {}, D extends object = {}>(): MergedComponent<P, D>
+ new <P = {}, D = {}>(): MergedComponent<P, D>
}
export type MergedComponent<P, D> = D & P & ComponentInstance<P, D>
export interface FunctionalComponent<P = {}> {
- (props: Readonly<P>, slots: Slots, attrs: Data): any
+ (props: P, slots: Slots, attrs: Data): any
pure?: boolean
props?: ComponentPropsOptions<P>
displayName?: string
import { ChildrenFlags } from './flags'
-import { ComponentClass, FunctionalComponent } from './component'
+import {
+ ComponentClass,
+ FunctionalComponent,
+ Component,
+ ComponentInstance
+} from './component'
import { ComponentOptions } from './componentOptions'
import {
VNode,
createComponentVNode,
createTextVNode,
createFragment,
- createPortal
+ createPortal,
+ VNodeData,
+ BuiltInProps
} from './vdom'
import { isObservable } from '@vue/observer'
import { warn } from './warning'
export const Fragment = Symbol()
export const Portal = Symbol()
-type ElementType =
+export type ElementType =
| string
| FunctionalComponent
| ComponentClass
| typeof Fragment
| typeof Portal
-export interface createElement {
- (tag: ElementType, data?: any, children?: any): VNode
+type RawChildType = VNode | string | number | boolean | null | undefined
+
+export type RawChildrenType = RawChildType | RawChildType[]
+
+interface VNodeFactories {
c: typeof createComponentVNode
e: typeof createElementVNode
t: typeof createTextVNode
p: typeof createPortal
}
+interface createElement {
+ // element
+ (tag: string, data?: VNodeData, children?: any): VNode
+ // functional
+ <P>(
+ tag: FunctionalComponent<P>,
+ data?: P & BuiltInProps | null,
+ children?: any
+ ): VNode
+ // stateful
+ <P, T extends ComponentInstance<P>>(
+ tag: new () => T & { $props: P },
+ data?: P & BuiltInProps | null,
+ children?: any
+ ): VNode
+}
+
export const h = ((tag: ElementType, data?: any, children?: any): VNode => {
if (
Array.isArray(data) ||
ref
)
}
-}) as createElement
+}) as createElement & VNodeFactories
h.c = createComponentVNode
h.e = createElementVNode
--- /dev/null
+import { ComponentInstance, ComponentType } from '../component'
+import { ComponentOptions } from '../componentOptions'
+import { RawVNodeChildren, VNodeData } from '../vdom'
+
+export interface Mixin extends ComponentOptions {}
+
+export function applyMixins(Component: ComponentInstance, mixins: Mixin[]) {}
+
+export function h(tag: ComponentType | string, data: RawVNodeChildren): object
+export function h(
+ tag: ComponentType | string,
+ data: VNodeData,
+ children: RawVNodeChildren
+): object {
+ return {}
+}
import { VNodeFlags, ChildrenFlags } from './flags'
import { createComponentClassFromOptions } from './componentUtils'
import { normalizeClass, normalizeStyle, handlersRE, EMPTY_OBJ } from './utils'
+import { ElementType, RawChildrenType } from './h'
// Vue core is platform agnostic, so we are not using Element for "DOM" nodes.
export interface RenderNode {
el: RenderNode
}
-export interface VNodeData {
+export interface BuiltInProps {
key?: Key | null
ref?: Ref | null
- slots?: Slots | null
- [key: string]: any
+ slots?: RawSlots | null
}
+export type VNodeData = Record<string, any> & BuiltInProps
+
export type VNodeChildren =
| VNode[] // ELEMENT | PORTAL
| ComponentInstance // COMPONENT_STATEFUL
| VNode // COMPONENT_FUNCTIONAL
| string // TEXT
- | null
-
-export type RawVNodeChildren = VNodeChildren | unknown[]
export type Key = string | number
[name: string]: Slot
}>
+export type RawSlots = {
+ [name: string]: () => RawChildrenType
+}
+
export function createVNode(
flags: VNodeFlags,
tag: string | FunctionalComponent | ComponentClass | RenderNode | null,
data: VNodeData | null,
- children: RawVNodeChildren | null,
+ children: RawChildrenType | null,
childFlags: ChildrenFlags,
key: Key | null | undefined,
ref: Ref | null | undefined,
export function createElementVNode(
tag: string,
data: VNodeData | null,
- children: RawVNodeChildren | null,
+ children: RawChildrenType | null,
childFlags: ChildrenFlags,
key?: Key | null,
ref?: Ref | null
export function createComponentVNode(
comp: any,
data: VNodeData | null,
- children: RawVNodeChildren | Slots,
+ children: RawChildrenType | Slots,
childFlags: ChildrenFlags,
key?: Key | null,
ref?: Ref | null
}
export function createFragment(
- children: RawVNodeChildren,
+ children: RawChildrenType,
childFlags?: ChildrenFlags,
key?: Key | null
) {
export function createPortal(
target: RenderNode | string,
- children: RawVNodeChildren,
+ children: RawChildrenType,
childFlags?: ChildrenFlags,
key?: Key | null,
ref?: Ref | null
flags,
vnode.tag,
clonedData,
- vnode.children,
+ vnode.children as RawChildrenType,
vnode.childFlags,
vnode.key,
vnode.ref,