watch,
watchEffect,
onUnmounted,
- onErrorCaptured
+ onErrorCaptured,
+ Component
} from '@vue/runtime-test'
describe('Suspense', () => {
setup(props: any, { slots }: any) {
const p = new Promise(resolve => {
setTimeout(() => {
- resolve(() => h(comp, props, slots))
+ resolve(() => h<Component>(comp, props, slots))
}, delay)
})
// in Node 12, due to timer/nextTick mechanism change, we have to wait
ComponentOptionsWithArrayProps,
ComponentOptionsWithObjectProps
} from './componentOptions'
-import { SetupContext, RenderFunction } from './component'
+import { SetupContext, RenderFunction, FunctionalComponent } from './component'
import { ComponentPublicInstance } from './componentProxy'
import { ExtractPropTypes, ComponentPropsOptions } from './componentProps'
import { EmitsOptions } from './componentEmits'
// public props
VNodeProps & Props
>
-}
+} & FunctionalComponent<Props>
// overload 2: object format with no props
// (uses user defined props interface)
E,
VNodeProps & Props
>
-}
+} & ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, EE>
// overload 3: object format with array props declaration
// props inferred as { [key in PropNames]?: any }
): {
// 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>
// overload 4: object format with object props declaration
// see `ExtractPropTypes` in ./componentProps.ts
E,
VNodeProps & ExtractPropTypes<PropsOptions, false>
>
-}
+} & ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, E, EE>
// implementation, close to no-op
export function defineComponent(options: unknown) {
new (): { $props: P }
}
+// Excludes Component type from returned `defineComponent`
+type NotDefinedComponent<T extends Component> = T extends Constructor
+ ? never
+ : T
+
// The following is a series of overloads for providing props validation of
// manually written render functions.
// catch-all for generic component types
export function h(type: Component, children?: RawChildren): VNode
-export function h(
- type: ComponentOptions | FunctionalComponent<{}>,
+
+// exclude `defineComponent`
+export function h<Options extends ComponentOptions | FunctionalComponent<{}>>(
+ type: NotDefinedComponent<Options>,
props?: RawProps | null,
children?: RawChildren | RawSlots
): VNode
-import { expectError } from 'tsd'
+import { expectError, expectAssignable } from 'tsd'
import {
describe,
h,
}
foo({})
})
+
+// #993
+describe('describeComponent extends Component', () => {
+ // functional
+ expectAssignable<Component>(
+ defineComponent((_props: { foo?: string; bar: number }) => {})
+ )
+
+ // typed props
+ expectAssignable<Component>(defineComponent({}))
+
+ // prop arrays
+ expectAssignable<Component>(
+ defineComponent({
+ props: ['a', 'b']
+ })
+ )
+
+ // prop object
+ expectAssignable<Component>(
+ defineComponent({
+ props: {
+ foo: String,
+ bar: {
+ type: Number,
+ required: true
+ }
+ }
+ })
+ )
+})