v3-define-component.d.ts 4.6 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. 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 0.0: functional component with array props
  70. */
  71. export function defineComponent<
  72. PropNames extends string,
  73. Props = Readonly<{ [key in PropNames]?: any }>
  74. >(options: {
  75. functional: true
  76. props?: PropNames[]
  77. render?: (h: CreateElement, context: RenderContext<Props>) => any
  78. }): DefineComponent<Props>
  79. /**
  80. * overload 0.1: functional component with object props
  81. */
  82. export function defineComponent<
  83. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions,
  84. Props = ExtractPropTypes<PropsOptions>
  85. >(options: {
  86. functional: true
  87. props?: PropsOptions
  88. render?: (h: CreateElement, context: RenderContext<Props>) => any
  89. }): DefineComponent<PropsOptions>
  90. /**
  91. * overload 1: object format with no props
  92. */
  93. export function defineComponent<
  94. RawBindings,
  95. D = Data,
  96. C extends ComputedOptions = {},
  97. M extends MethodOptions = {},
  98. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  99. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  100. Emits extends EmitsOptions = {},
  101. EmitsNames extends string = string
  102. >(
  103. options: ComponentOptionsWithoutProps<
  104. {},
  105. RawBindings,
  106. D,
  107. C,
  108. M,
  109. Mixin,
  110. Extends,
  111. Emits,
  112. EmitsNames
  113. >
  114. ): DefineComponent<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
  115. /**
  116. * overload 2: object format with array props declaration
  117. * props inferred as `{ [key in PropNames]?: any }`
  118. *
  119. * return type is for Vetur and TSX support
  120. */
  121. export function defineComponent<
  122. PropNames extends string,
  123. RawBindings = Data,
  124. D = Data,
  125. C extends ComputedOptions = {},
  126. M extends MethodOptions = {},
  127. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  128. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  129. Emits extends EmitsOptions = {},
  130. EmitsNames extends string = string,
  131. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
  132. >(
  133. options: ComponentOptionsWithArrayProps<
  134. PropNames,
  135. RawBindings,
  136. D,
  137. C,
  138. M,
  139. Mixin,
  140. Extends,
  141. Emits,
  142. EmitsNames
  143. >
  144. ): DefineComponent<
  145. Readonly<{ [key in PropNames]?: any }>,
  146. RawBindings,
  147. D,
  148. C,
  149. M,
  150. Mixin,
  151. Extends,
  152. Emits
  153. >
  154. /**
  155. * overload 3: object format with object props declaration
  156. *
  157. * see `ExtractPropTypes` in './componentProps.ts'
  158. */
  159. export function defineComponent<
  160. Props,
  161. RawBindings = Data,
  162. D = Data,
  163. C extends ComputedOptions = {},
  164. M extends MethodOptions = {},
  165. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  166. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  167. Emits extends EmitsOptions = {},
  168. EmitsNames extends string = string,
  169. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
  170. >(
  171. options: HasDefined<Props> extends true
  172. ? ComponentOptionsWithProps<
  173. PropsOptions,
  174. RawBindings,
  175. D,
  176. C,
  177. M,
  178. Mixin,
  179. Extends,
  180. Emits,
  181. EmitsNames,
  182. Props
  183. >
  184. : ComponentOptionsWithProps<
  185. PropsOptions,
  186. RawBindings,
  187. D,
  188. C,
  189. M,
  190. Mixin,
  191. Extends,
  192. Emits,
  193. EmitsNames
  194. >
  195. ): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>