options.d.ts 2.7 KB

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