options.d.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { Vue } from "./vue";
  2. import { VNode, VNodeData, VNodeDirective } from "./vnode";
  3. type Constructor = {
  4. new (...args: any[]): any;
  5. }
  6. type $createElement = typeof Vue.prototype.$createElement;
  7. export type Component = typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions;
  8. export type AsyncComponent = (
  9. resolve: (component: Component) => void,
  10. reject: (reason?: any) => void
  11. ) => Promise<Component> | Component | void;
  12. export interface ComponentOptions<V extends Vue> {
  13. data?: Object | ((this: V) => Object);
  14. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  15. propsData?: Object;
  16. computed?: { [key: string]: ((this: V) => any) | ComputedOptions<V> };
  17. methods?: { [key: string]: Function };
  18. watch?: { [key: string]: ({ handler: WatchHandler<V> } & WatchOptions) | WatchHandler<V> | string };
  19. el?: Element | String;
  20. template?: string;
  21. render?(this: V, createElement: $createElement): VNode;
  22. staticRenderFns?: ((createElement: $createElement) => VNode)[];
  23. beforeCreate?(this: V): void;
  24. created?(this: V): void;
  25. beforeDestroy?(this: V): void;
  26. destroyed?(this: V): void;
  27. beforeMount?(this: V): void;
  28. mounted?(this: V): void;
  29. beforeUpdate?(this: V): void;
  30. updated?(this: V): void;
  31. directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
  32. components?: { [key: string]: Component | AsyncComponent };
  33. transitions?: { [key: string]: Object };
  34. filters?: { [key: string]: Function };
  35. parent?: Vue;
  36. mixins?: (ComponentOptions<Vue> | typeof Vue)[];
  37. name?: string;
  38. extends?: ComponentOptions<Vue> | typeof Vue;
  39. delimiters?: [string, string];
  40. }
  41. export interface FunctionalComponentOptions {
  42. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  43. functional: boolean;
  44. render(this: never, createElement: $createElement, context: RenderContext): VNode;
  45. name?: string;
  46. }
  47. export interface RenderContext {
  48. props: any;
  49. children: VNode[];
  50. slots: any;
  51. data: VNodeData;
  52. parent: Vue;
  53. }
  54. export interface PropOptions {
  55. type?: Constructor | Constructor[] | null;
  56. required?: boolean;
  57. default?: any;
  58. validator?(value: any): boolean;
  59. }
  60. export interface ComputedOptions<V> {
  61. get?(this: V): any;
  62. set?(this: V, value: any): void;
  63. cache?: boolean;
  64. }
  65. export type WatchHandler<V> = (this: V, val: any, oldVal: any) => void;
  66. export interface WatchOptions {
  67. deep?: boolean;
  68. immediate?: boolean;
  69. }
  70. export type DirectiveFunction = (
  71. el: HTMLElement,
  72. binding: VNodeDirective,
  73. vnode: VNode,
  74. oldVnode: VNode
  75. ) => void;
  76. export interface DirectiveOptions {
  77. bind?: DirectiveFunction;
  78. inserted?: DirectiveFunction;
  79. update?: DirectiveFunction;
  80. componentUpdated?: DirectiveFunction;
  81. unbind?: DirectiveFunction;
  82. }