Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

options.d.ts 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import { Vue, CreateElement, CombinedVueInstance } from "./vue";
  2. import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from "./vnode";
  3. type Constructor = {
  4. new (...args: any[]): any;
  5. }
  6. // we don't support infer props in async component
  7. // N.B. ComponentOptions<V> is contravariant, the default generic should be bottom type
  8. export type Component<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> =
  9. | typeof Vue
  10. | FunctionalComponentOptions<Props>
  11. | ComponentOptions<never, Data, Methods, Computed, Props>
  12. interface EsModuleComponent {
  13. default: Component
  14. }
  15. export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps>
  16. = AsyncComponentPromise<Data, Methods, Computed, Props>
  17. | AsyncComponentFactory<Data, Methods, Computed, Props>
  18. export type AsyncComponentPromise<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = (
  19. resolve: (component: Component<Data, Methods, Computed, Props>) => void,
  20. reject: (reason?: any) => void
  21. ) => Promise<Component | EsModuleComponent> | void;
  22. export type AsyncComponentFactory<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = () => {
  23. component: AsyncComponentPromise<Data, Methods, Computed, Props>;
  24. loading?: Component | EsModuleComponent;
  25. error?: Component | EsModuleComponent;
  26. delay?: number;
  27. timeout?: number;
  28. }
  29. /**
  30. * When the `Computed` type parameter on `ComponentOptions` is inferred,
  31. * it should have a property with the return type of every get-accessor.
  32. * Since there isn't a way to query for the return type of a function, we allow TypeScript
  33. * to infer from the shape of `Accessors<Computed>` and work backwards.
  34. */
  35. export type Accessors<T> = {
  36. [K in keyof T]: (() => T[K]) | ComputedOptions<T[K]>
  37. }
  38. type DataDef<Data, Props, V> = Data | ((this: Readonly<Props> & V) => Data)
  39. /**
  40. * This type should be used when an array of strings is used for a component's `props` value.
  41. */
  42. export type ThisTypedComponentOptionsWithArrayProps<V extends Vue, Data, Methods, Computed, PropNames extends string> =
  43. object &
  44. ComponentOptions<V, DataDef<Data, Record<PropNames, any>, V>, Methods, Computed, PropNames[], Record<PropNames, any>> &
  45. ThisType<CombinedVueInstance<V, Data, Methods, Computed, Readonly<Record<PropNames, any>>>>;
  46. /**
  47. * This type should be used when an object mapped to `PropOptions` is used for a component's `props` value.
  48. */
  49. export type ThisTypedComponentOptionsWithRecordProps<V extends Vue, Data, Methods, Computed, Props> =
  50. object &
  51. ComponentOptions<V, DataDef<Data, Props, V>, Methods, Computed, RecordPropsDefinition<Props>, Props> &
  52. ThisType<CombinedVueInstance<V, Data, Methods, Computed, Readonly<Props>>>;
  53. type DefaultData<V> = object | ((this: V) => object);
  54. type DefaultProps = Record<string, any>;
  55. type DefaultMethods<V> = { [key: string]: (this: V, ...args: any[]) => any };
  56. type DefaultComputed = { [key: string]: any };
  57. export interface ComponentOptions<
  58. V extends Vue,
  59. Data=DefaultData<V>,
  60. Methods=DefaultMethods<V>,
  61. Computed=DefaultComputed,
  62. PropsDef=PropsDefinition<DefaultProps>,
  63. Props=DefaultProps> {
  64. data?: Data;
  65. props?: PropsDef;
  66. propsData?: object;
  67. computed?: Accessors<Computed>;
  68. methods?: Methods;
  69. watch?: Record<string, WatchOptionsWithHandler<any> | WatchHandler<any> | string>;
  70. el?: Element | string;
  71. template?: string;
  72. // hack is for functional component type inference, should not be used in user code
  73. render?(createElement: CreateElement, hack: RenderContext<Props>): VNode;
  74. renderError?(createElement: CreateElement, err: Error): VNode;
  75. staticRenderFns?: ((createElement: CreateElement) => VNode)[];
  76. beforeCreate?(this: V): void;
  77. created?(): void;
  78. beforeDestroy?(): void;
  79. destroyed?(): void;
  80. beforeMount?(): void;
  81. mounted?(): void;
  82. beforeUpdate?(): void;
  83. updated?(): void;
  84. activated?(): void;
  85. deactivated?(): void;
  86. errorCaptured?(err: Error, vm: Vue, info: string): boolean | void;
  87. serverPrefetch?(this: V): Promise<void>;
  88. directives?: { [key: string]: DirectiveFunction | DirectiveOptions };
  89. components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> };
  90. transitions?: { [key: string]: object };
  91. filters?: { [key: string]: Function };
  92. provide?: object | (() => object);
  93. inject?: InjectOptions;
  94. model?: {
  95. prop?: string;
  96. event?: string;
  97. };
  98. parent?: Vue;
  99. mixins?: (ComponentOptions<Vue> | typeof Vue)[];
  100. name?: string;
  101. // TODO: support properly inferred 'extends'
  102. extends?: ComponentOptions<Vue> | typeof Vue;
  103. delimiters?: [string, string];
  104. comments?: boolean;
  105. inheritAttrs?: boolean;
  106. }
  107. export interface FunctionalComponentOptions<Props = DefaultProps, PropDefs = PropsDefinition<Props>> {
  108. name?: string;
  109. props?: PropDefs;
  110. model?: {
  111. prop?: string;
  112. event?: string;
  113. };
  114. inject?: InjectOptions;
  115. functional: boolean;
  116. render?(this: undefined, createElement: CreateElement, context: RenderContext<Props>): VNode | VNode[];
  117. }
  118. export interface RenderContext<Props=DefaultProps> {
  119. props: Props;
  120. children: VNode[];
  121. slots(): any;
  122. data: VNodeData;
  123. parent: Vue;
  124. listeners: { [key: string]: Function | Function[] };
  125. scopedSlots: { [key: string]: NormalizedScopedSlot };
  126. injections: any
  127. }
  128. export type Prop<T> = { (): T } | { new(...args: any[]): T & object } | { new(...args: string[]): Function }
  129. export type PropType<T> = Prop<T> | Prop<T>[];
  130. export type PropValidator<T> = PropOptions<T> | PropType<T>;
  131. export interface PropOptions<T=any> {
  132. type?: PropType<T>;
  133. required?: boolean;
  134. default?: T | null | undefined | (() => T | null | undefined);
  135. validator?(value: T): boolean;
  136. }
  137. export type RecordPropsDefinition<T> = {
  138. [K in keyof T]: PropValidator<T[K]>
  139. }
  140. export type ArrayPropsDefinition<T> = (keyof T)[];
  141. export type PropsDefinition<T> = ArrayPropsDefinition<T> | RecordPropsDefinition<T>;
  142. export interface ComputedOptions<T> {
  143. get?(): T;
  144. set?(value: T): void;
  145. cache?: boolean;
  146. }
  147. export type WatchHandler<T> = (val: T, oldVal: T) => void;
  148. export interface WatchOptions {
  149. deep?: boolean;
  150. immediate?: boolean;
  151. }
  152. export interface WatchOptionsWithHandler<T> extends WatchOptions {
  153. handler: WatchHandler<T>;
  154. }
  155. export interface DirectiveBinding extends Readonly<VNodeDirective> {
  156. readonly modifiers: { [key: string]: boolean };
  157. }
  158. export type DirectiveFunction = (
  159. el: HTMLElement,
  160. binding: DirectiveBinding,
  161. vnode: VNode,
  162. oldVnode: VNode
  163. ) => void;
  164. export interface DirectiveOptions {
  165. bind?: DirectiveFunction;
  166. inserted?: DirectiveFunction;
  167. update?: DirectiveFunction;
  168. componentUpdated?: DirectiveFunction;
  169. unbind?: DirectiveFunction;
  170. }
  171. export type InjectKey = string | symbol;
  172. export type InjectOptions = {
  173. [key: string]: InjectKey | { from?: InjectKey, default?: any }
  174. } | string[];