Skip to content

Commit

Permalink
types: fix defineComponent return type
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed May 1, 2020
1 parent 3193816 commit 11cd53d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 9 additions & 4 deletions packages/runtime-core/src/apiDefineComponent.ts
Expand Up @@ -5,7 +5,12 @@ import {
ComponentOptionsWithArrayProps,
ComponentOptionsWithObjectProps
} from './componentOptions'
import { SetupContext, RenderFunction, FunctionalComponent } from './component'
import {
SetupContext,
RenderFunction,
FunctionalComponent,
DefineComponent
} from './component'
import { ComponentPublicInstance } from './componentProxy'
import { ExtractPropTypes, ComponentPropsOptions } from './componentProps'
import { EmitsOptions } from './componentEmits'
Expand Down Expand Up @@ -59,7 +64,7 @@ export function defineComponent<
E,
VNodeProps & Props
>
} & ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, EE>
} & DefineComponent //& ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, EE>

// overload 3: object format with array props declaration
// props inferred as { [key in PropNames]?: any }
Expand All @@ -85,7 +90,7 @@ export function defineComponent<
): {
// array props technically doesn't place any contraints on props in TSX
new (): ComponentPublicInstance<VNodeProps, RawBindings, D, C, M, E>
} & ComponentOptionsWithArrayProps<PropNames, RawBindings, D, C, M, E, EE>
} & DefineComponent //& ComponentOptionsWithArrayProps<PropNames, RawBindings, D, C, M, E, EE>

// overload 4: object format with object props declaration
// see `ExtractPropTypes` in ./componentProps.ts
Expand Down Expand Up @@ -119,7 +124,7 @@ export function defineComponent<
E,
VNodeProps & ExtractPropTypes<PropsOptions, false>
>
} & ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, E, EE>
} & DefineComponent //& ComponentOptionsBase<PropsOptions, RawBindings, D, C, M, E, EE>

// implementation, close to no-op
export function defineComponent(options: unknown) {
Expand Down
12 changes: 11 additions & 1 deletion packages/runtime-core/src/component.ts
Expand Up @@ -71,7 +71,17 @@ export interface ClassComponent {
__vccOpts: ComponentOptions
}

export type Component = ComponentOptions | FunctionalComponent<any>
// Allow typescript deferenciate DefineComponent from other interfaces
declare const DefineComponentSymbol: unique symbol
export interface DefineComponent {
[DefineComponentSymbol]: true
[key: string]: any
}

export type Component =
| ComponentOptions
| FunctionalComponent<any>
| DefineComponent

// A type used in public APIs where a component type is expected.
// The constructor type is an artificial type returned by defineComponent().
Expand Down

0 comments on commit 11cd53d

Please sign in to comment.