options.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
  31. components?: { [key: string]: Component | AsyncComponent };
  32. transitions?: { [key: string]: Object };
  33. filters?: { [key: string]: Function };
  34. parent?: Vue;
  35. mixins?: (ComponentOptions<Vue> | typeof Vue)[];
  36. name?: string;
  37. extends?: ComponentOptions<Vue> | typeof Vue;
  38. delimiters?: [string, string];
  39. }
  40. export interface FunctionalComponentOptions {
  41. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  42. functional: boolean;
  43. render(this: never, createElement: CreateElement, context: RenderContext): VNode;
  44. name?: string;
  45. }
  46. export interface RenderContext {
  47. props: any;
  48. children: VNode[];
  49. slots: any;
  50. data: VNodeData;
  51. parent: Vue;
  52. }
  53. export interface PropOptions {
  54. type?: Constructor | Constructor[] | null;
  55. required?: boolean;
  56. default?: any;
  57. validator?(value: any): boolean;
  58. }
  59. export interface ComputedOptions<V> {
  60. get?(this: V): any;
  61. set?(this: V, value: any): void;
  62. cache?: boolean;
  63. }
  64. export type WatchHandler<V> = (this: V, val: any, oldVal: any) => void;
  65. export interface WatchOptions {
  66. deep?: boolean;
  67. immediate?: boolean;
  68. }
  69. export type DirectiveFunction = (
  70. el: HTMLElement,
  71. binding: VNodeDirective,
  72. vnode: VNode,
  73. oldVnode: VNode
  74. ) => void;
  75. export interface DirectiveOptions {
  76. bind?: DirectiveFunction;
  77. inserted?: DirectiveFunction;
  78. update?: DirectiveFunction;
  79. componentUpdated?: DirectiveFunction;
  80. unbind?: DirectiveFunction;
  81. }