v3-define-component.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {
  2. ComponentPropsOptions,
  3. ExtractDefaultPropTypes,
  4. ExtractPropTypes
  5. } from './v3-component-props'
  6. import {
  7. MethodOptions,
  8. ComputedOptions,
  9. ComponentOptionsWithoutProps,
  10. ComponentOptionsWithArrayProps,
  11. ComponentOptionsWithProps,
  12. ComponentOptionsMixin,
  13. ComponentOptionsBase
  14. } from './v3-component-options'
  15. import {
  16. ComponentPublicInstanceConstructor,
  17. CreateComponentPublicInstance
  18. } from './v3-component-public-instance'
  19. import { Data, HasDefined } from './common'
  20. import { EmitsOptions } from './v3-setup-context'
  21. import { CreateElement, RenderContext } from './umd'
  22. export type DefineComponent<
  23. PropsOrPropOptions = {},
  24. RawBindings = {},
  25. D = {},
  26. C extends ComputedOptions = ComputedOptions,
  27. M extends MethodOptions = MethodOptions,
  28. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  29. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  30. E extends EmitsOptions = {},
  31. EE extends string = string,
  32. Props = Readonly<
  33. PropsOrPropOptions extends ComponentPropsOptions
  34. ? ExtractPropTypes<PropsOrPropOptions>
  35. : PropsOrPropOptions
  36. >,
  37. Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
  38. > = ComponentPublicInstanceConstructor<
  39. CreateComponentPublicInstance<
  40. Props,
  41. RawBindings,
  42. D,
  43. C,
  44. M,
  45. Mixin,
  46. Extends,
  47. E,
  48. Props,
  49. Defaults,
  50. true
  51. > &
  52. Props
  53. > &
  54. ComponentOptionsBase<
  55. Props,
  56. RawBindings,
  57. D,
  58. C,
  59. M,
  60. Mixin,
  61. Extends,
  62. E,
  63. EE,
  64. Defaults
  65. > & {
  66. props: PropsOrPropOptions
  67. }
  68. /**
  69. * overload 1: object format with no props
  70. */
  71. export function defineComponent<
  72. RawBindings,
  73. D = {},
  74. C extends ComputedOptions = {},
  75. M extends MethodOptions = {},
  76. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  77. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  78. Emits extends EmitsOptions = {},
  79. EmitsNames extends string = string
  80. >(
  81. options: { functional?: never } & ComponentOptionsWithoutProps<
  82. {},
  83. RawBindings,
  84. D,
  85. C,
  86. M,
  87. Mixin,
  88. Extends,
  89. Emits,
  90. EmitsNames
  91. >
  92. ): DefineComponent<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
  93. /**
  94. * overload 2: object format with array props declaration
  95. * props inferred as `{ [key in PropNames]?: any }`
  96. *
  97. * return type is for Vetur and TSX support
  98. */
  99. export function defineComponent<
  100. PropNames extends string,
  101. RawBindings = {},
  102. D = {},
  103. C extends ComputedOptions = {},
  104. M extends MethodOptions = {},
  105. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  106. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  107. Emits extends EmitsOptions = {},
  108. EmitsNames extends string = string,
  109. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
  110. >(
  111. options: { functional?: never } & ComponentOptionsWithArrayProps<
  112. PropNames,
  113. RawBindings,
  114. D,
  115. C,
  116. M,
  117. Mixin,
  118. Extends,
  119. Emits,
  120. EmitsNames
  121. >
  122. ): DefineComponent<
  123. Readonly<{ [key in PropNames]?: any }>,
  124. RawBindings,
  125. D,
  126. C,
  127. M,
  128. Mixin,
  129. Extends,
  130. Emits
  131. >
  132. /**
  133. * overload 3: object format with object props declaration
  134. *
  135. * see `ExtractPropTypes` in './componentProps.ts'
  136. */
  137. export function defineComponent<
  138. Props,
  139. RawBindings = {},
  140. D = {},
  141. C extends ComputedOptions = {},
  142. M extends MethodOptions = {},
  143. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  144. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  145. Emits extends EmitsOptions = {},
  146. EmitsNames extends string = string,
  147. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
  148. >(
  149. options: HasDefined<Props> extends true
  150. ? { functional?: never } & ComponentOptionsWithProps<
  151. PropsOptions,
  152. RawBindings,
  153. D,
  154. C,
  155. M,
  156. Mixin,
  157. Extends,
  158. Emits,
  159. EmitsNames,
  160. Props
  161. >
  162. : { functional?: never } & ComponentOptionsWithProps<
  163. PropsOptions,
  164. RawBindings,
  165. D,
  166. C,
  167. M,
  168. Mixin,
  169. Extends,
  170. Emits,
  171. EmitsNames
  172. >
  173. ): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>
  174. /**
  175. * overload 4.1: functional component with array props
  176. */
  177. export function defineComponent<
  178. PropNames extends string,
  179. Props = Readonly<{ [key in PropNames]?: any }>
  180. >(options: {
  181. functional: true
  182. props?: PropNames[]
  183. render?: (h: CreateElement, context: RenderContext<Props>) => any
  184. }): DefineComponent<Props>
  185. /**
  186. * overload 4.2: functional component with object props
  187. */
  188. export function defineComponent<
  189. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions,
  190. Props = ExtractPropTypes<PropsOptions>
  191. >(options: {
  192. functional: true
  193. props?: PropsOptions
  194. render?: (h: CreateElement, context: RenderContext<Props>) => any
  195. }): DefineComponent<PropsOptions>