v3-define-component.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. type DefineComponent<
  22. PropsOrPropOptions = {},
  23. RawBindings = {},
  24. D = {},
  25. C extends ComputedOptions = ComputedOptions,
  26. M extends MethodOptions = MethodOptions,
  27. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  28. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  29. E extends EmitsOptions = {},
  30. EE extends string = string,
  31. Props = Readonly<
  32. PropsOrPropOptions extends ComponentPropsOptions
  33. ? ExtractPropTypes<PropsOrPropOptions>
  34. : PropsOrPropOptions
  35. >,
  36. Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
  37. > = ComponentPublicInstanceConstructor<
  38. CreateComponentPublicInstance<
  39. Props,
  40. RawBindings,
  41. D,
  42. C,
  43. M,
  44. Mixin,
  45. Extends,
  46. E,
  47. Props,
  48. Defaults,
  49. true
  50. > &
  51. Props
  52. > &
  53. ComponentOptionsBase<
  54. Props,
  55. RawBindings,
  56. D,
  57. C,
  58. M,
  59. Mixin,
  60. Extends,
  61. E,
  62. EE,
  63. Defaults
  64. > & {
  65. props: PropsOrPropOptions
  66. }
  67. /**
  68. * overload 1: object format with no props
  69. */
  70. export function defineComponent<
  71. RawBindings,
  72. D = Data,
  73. C extends ComputedOptions = {},
  74. M extends MethodOptions = {},
  75. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  76. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  77. Emits extends EmitsOptions = {},
  78. EmitsNames extends string = string
  79. >(
  80. options: ComponentOptionsWithoutProps<
  81. {},
  82. RawBindings,
  83. D,
  84. C,
  85. M,
  86. Mixin,
  87. Extends,
  88. Emits,
  89. EmitsNames
  90. >
  91. ): DefineComponent<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
  92. /**
  93. * overload 2: object format with array props declaration
  94. * props inferred as `{ [key in PropNames]?: any }`
  95. *
  96. * return type is for Vetur and TSX support
  97. */
  98. export function defineComponent<
  99. PropNames extends string,
  100. RawBindings = Data,
  101. D = Data,
  102. C extends ComputedOptions = {},
  103. M extends MethodOptions = {},
  104. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  105. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  106. Emits extends EmitsOptions = {},
  107. EmitsNames extends string = string,
  108. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
  109. >(
  110. options: ComponentOptionsWithArrayProps<
  111. PropNames,
  112. RawBindings,
  113. D,
  114. C,
  115. M,
  116. Mixin,
  117. Extends,
  118. Emits,
  119. EmitsNames
  120. >
  121. ): DefineComponent<
  122. Readonly<{ [key in PropNames]?: any }>,
  123. RawBindings,
  124. D,
  125. C,
  126. M,
  127. Mixin,
  128. Extends,
  129. Emits
  130. >
  131. /**
  132. * overload 3: object format with object props declaration
  133. *
  134. * see `ExtractPropTypes` in './componentProps.ts'
  135. */
  136. export function defineComponent<
  137. Props,
  138. RawBindings = Data,
  139. D = Data,
  140. C extends ComputedOptions = {},
  141. M extends MethodOptions = {},
  142. Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
  143. Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
  144. Emits extends EmitsOptions = {},
  145. EmitsNames extends string = string,
  146. PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
  147. >(
  148. options: HasDefined<Props> extends true
  149. ? ComponentOptionsWithProps<
  150. PropsOptions,
  151. RawBindings,
  152. D,
  153. C,
  154. M,
  155. Mixin,
  156. Extends,
  157. Emits,
  158. EmitsNames,
  159. Props
  160. >
  161. : ComponentOptionsWithProps<
  162. PropsOptions,
  163. RawBindings,
  164. D,
  165. C,
  166. M,
  167. Mixin,
  168. Extends,
  169. Emits,
  170. EmitsNames
  171. >
  172. ): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>