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 5.8KB

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