v3-setup-context.d.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { VNode } from './vnode'
  2. import { Data, UnionToIntersection } from './common'
  3. import { Vue } from './vue'
  4. export type Slot = (...args: any[]) => VNode[]
  5. export type Slots = Record<string, Slot | undefined>
  6. export type ObjectEmitsOptions = Record<
  7. string,
  8. ((...args: any[]) => any) | null
  9. >
  10. export type EmitsOptions = ObjectEmitsOptions | string[]
  11. export type EmitFn<
  12. Options = ObjectEmitsOptions,
  13. Event extends keyof Options = keyof Options,
  14. ReturnType extends void | Vue = void
  15. > = Options extends Array<infer V>
  16. ? (event: V, ...args: any[]) => ReturnType
  17. : {} extends Options // if the emit is empty object (usually the default value for emit) should be converted to function
  18. ? (event: string, ...args: any[]) => ReturnType
  19. : UnionToIntersection<
  20. {
  21. [key in Event]: Options[key] extends (...args: infer Args) => any
  22. ? (event: key, ...args: Args) => ReturnType
  23. : (event: key, ...args: any[]) => ReturnType
  24. }[Event]
  25. >
  26. export interface SetupContext<E extends EmitsOptions = {}> {
  27. attrs: Data
  28. /**
  29. * Equivalent of `this.$listeners`, which is Vue 2 only.
  30. */
  31. listeners: Record<string, Function | Function[]>
  32. slots: Slots
  33. emit: EmitFn<E>
  34. expose(exposed?: Record<string, any>): void
  35. }