options.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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, any> } & WatchOptions) | WatchHandler<V, any> | string };
  18. el?: Element | String;
  19. template?: string;
  20. render?(this: V, createElement: CreateElement): VNode;
  21. renderError?: (h: () => VNode, err: Error) => 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. activated?(this: V): void;
  32. deactivated?(this: V): void;
  33. directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
  34. components?: { [key: string]: Component | AsyncComponent };
  35. transitions?: { [key: string]: Object };
  36. filters?: { [key: string]: Function };
  37. provide?: Object | (() => Object);
  38. inject?: { [key: string]: string | symbol } | Array<string>;
  39. model?: {
  40. prop?: string;
  41. event?: string;
  42. };
  43. parent?: Vue;
  44. mixins?: (ComponentOptions<Vue> | typeof Vue)[];
  45. name?: string;
  46. extends?: ComponentOptions<Vue> | typeof Vue;
  47. delimiters?: [string, string];
  48. }
  49. export interface FunctionalComponentOptions {
  50. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  51. functional: boolean;
  52. render(this: never, createElement: CreateElement, context: RenderContext): VNode;
  53. name?: string;
  54. }
  55. export interface RenderContext {
  56. props: any;
  57. children: VNode[];
  58. slots(): any;
  59. data: VNodeData;
  60. parent: Vue;
  61. injections: any
  62. }
  63. export interface PropOptions {
  64. type?: Constructor | Constructor[] | null;
  65. required?: boolean;
  66. default?: any;
  67. validator?(value: any): boolean;
  68. }
  69. export interface ComputedOptions<V> {
  70. get?(this: V): any;
  71. set?(this: V, value: any): void;
  72. cache?: boolean;
  73. }
  74. export type WatchHandler<V, T> = (this: V, val: T, oldVal: T) => void;
  75. export interface WatchOptions {
  76. deep?: boolean;
  77. immediate?: boolean;
  78. }
  79. export type DirectiveFunction = (
  80. el: HTMLElement,
  81. binding: VNodeDirective,
  82. vnode: VNode,
  83. oldVnode: VNode
  84. ) => void;
  85. export interface DirectiveOptions {
  86. bind?: DirectiveFunction;
  87. inserted?: DirectiveFunction;
  88. update?: DirectiveFunction;
  89. componentUpdated?: DirectiveFunction;
  90. unbind?: DirectiveFunction;
  91. }