diff --git a/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx b/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx index 3fd21122..3918d742 100644 --- a/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx +++ b/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx @@ -35,7 +35,7 @@ test('createComponent type inference', () => { type: Array as () => string[], required: true } - } as const, // required to narrow for conditional check + }, setup(props) { props.a && props.a * 2 props.b.slice() diff --git a/packages/runtime-core/src/apiCreateComponent.ts b/packages/runtime-core/src/apiCreateComponent.ts index 6618837b..c1503278 100644 --- a/packages/runtime-core/src/apiCreateComponent.ts +++ b/packages/runtime-core/src/apiCreateComponent.ts @@ -7,18 +7,15 @@ import { } from './apiOptions' import { SetupContext, RenderFunction } from './component' import { ComponentPublicInstance } from './componentProxy' -import { ExtractPropTypes } from './componentProps' +import { ExtractPropTypes, ComponentPropsOptions } from './componentProps' import { isFunction } from '@vue/shared' import { VNodeProps } from './vnode' // overload 1: direct setup function // (uses user defined props interface) -// __isConstructor: true is a type-only differentiator to avoid returned -// constructor type from being matched as an options object in h() export function createComponent( setup: (props: Props, ctx: SetupContext) => RawBindings | RenderFunction ): { - __isConstructor: true new (): ComponentPublicInstance< Props, RawBindings, @@ -42,7 +39,6 @@ export function createComponent< >( options: ComponentOptionsWithoutProps ): { - __isConstructor: true new (): ComponentPublicInstance< Props, RawBindings, @@ -65,7 +61,6 @@ export function createComponent< >( options: ComponentOptionsWithArrayProps ): { - __isConstructor: true // array props technically doesn't place any contraints on props in TSX new (): ComponentPublicInstance } @@ -73,7 +68,7 @@ export function createComponent< // overload 4: object format with object props declaration // see `ExtractPropTypes` in ./componentProps.ts export function createComponent< - PropsOptions, + PropsOptions extends Readonly, RawBindings, D, C extends ComputedOptions = {}, @@ -81,10 +76,9 @@ export function createComponent< >( options: ComponentOptionsWithObjectProps ): { - __isConstructor: true // for Vetur and TSX support new (): ComponentPublicInstance< - ExtractPropTypes, + ExtractPropTypes, RawBindings, D, C, diff --git a/packages/runtime-core/src/apiOptions.ts b/packages/runtime-core/src/apiOptions.ts index 7f764ddc..d094f50f 100644 --- a/packages/runtime-core/src/apiOptions.ts +++ b/packages/runtime-core/src/apiOptions.ts @@ -67,8 +67,8 @@ export interface ComponentOptionsBase< inheritAttrs?: boolean // type-only differentiator to separate OptionWihtoutProps from a constructor - // type returned by createComponent() - __isConstructor?: never + // type returned by createComponent() or FunctionalComponent + call?: never } export type ComponentOptionsWithoutProps< diff --git a/packages/runtime-core/src/h.ts b/packages/runtime-core/src/h.ts index 8b795395..27045476 100644 --- a/packages/runtime-core/src/h.ts +++ b/packages/runtime-core/src/h.ts @@ -1,5 +1,4 @@ import { - VNodeTypes, VNode, VNodeProps, createVNode, @@ -146,11 +145,7 @@ export function h

( ): VNode // Actual implementation -export function h( - type: VNodeTypes, - propsOrChildren?: any, - children?: any -): VNode { +export function h(type: any, propsOrChildren?: any, children?: any): VNode { if (arguments.length === 2) { if (isObject(propsOrChildren) && !isArray(propsOrChildren)) { // single vnode without props