export interface FunctionalComponent<
P = {},
- E extends EmitsOptions = Record<string, any>
+ E extends EmitsOptions = {}
> extends ComponentInternalOptions {
// use of any here is intentional so it can be a valid JSX Element constructor
(props: P, ctx: SetupContext<E>): any
Event extends keyof Options = keyof Options
> = Options extends any[]
? (event: Options[0], ...args: any[]) => void
- : UnionToIntersection<
- {
- [key in Event]: Options[key] extends ((...args: infer Args) => any)
- ? (event: key, ...args: Args) => void
- : (event: key, ...args: any[]) => void
- }[Event]
- >
+ : {} extends Options // if the emit is empty object (usually the default value for emit) should be converted to function
+ ? (event: string, ...args: any[]) => void
+ : UnionToIntersection<
+ {
+ [key in Event]: Options[key] extends ((...args: infer Args) => any)
+ ? (event: key, ...args: Args) => void
+ : (event: key, ...args: any[]) => void
+ }[Event]
+ >
export function emit(
instance: ComponentInternalInstance,
import { RawSlots } from './componentSlots'
import { FunctionalComponent, Component } from './component'
import { ComponentOptions } from './componentOptions'
+import { EmitsOptions } from './componentEmits'
// `h` is a more user-friendly version of `createVNode` that allows omitting the
// props when possible. It is intended for manually written render functions.
): VNode
// functional component
-export function h<P>(
- type: FunctionalComponent<P>,
+export function h<P, E extends EmitsOptions = {}>(
+ type: FunctionalComponent<P, E>,
props?: (RawProps & P) | ({} extends P ? null : never),
children?: RawChildren | RawSlots
): VNode
reactive,
createApp,
expectError,
- expectType
+ expectType,
+ ComponentPublicInstance
} from './index'
describe('with object props', () => {
expectError(this.$emit('nope'))
}
})
+
+ // without emits
+ defineComponent({
+ setup(props, { emit }) {
+ emit('test', 1)
+ emit('test')
+ }
+ })
+
+ // emit should be valid when ComponentPublicInstance is used.
+ const instance = {} as ComponentPublicInstance
+ instance.$emit('test', 1)
+ instance.$emit('test')
})