options.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. comments?: boolean;
  49. inheritAttrs?: boolean;
  50. }
  51. export interface FunctionalComponentOptions {
  52. name?: string;
  53. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  54. functional: boolean;
  55. render(this: never, createElement: CreateElement, context: RenderContext): VNode | void;
  56. }
  57. export interface RenderContext {
  58. props: any;
  59. children: VNode[];
  60. slots(): any;
  61. data: VNodeData;
  62. parent: Vue;
  63. injections: any
  64. }
  65. export interface PropOptions {
  66. type?: Constructor | Constructor[] | null;
  67. required?: boolean;
  68. default?: any;
  69. validator?(value: any): boolean;
  70. }
  71. export interface ComputedOptions<V> {
  72. get?(this: V): any;
  73. set?(this: V, value: any): void;
  74. cache?: boolean;
  75. }
  76. export type WatchHandler<V, T> = (this: V, val: T, oldVal: T) => void;
  77. export interface WatchOptions {
  78. deep?: boolean;
  79. immediate?: boolean;
  80. }
  81. export type DirectiveFunction = (
  82. el: HTMLElement,
  83. binding: VNodeDirective,
  84. vnode: VNode,
  85. oldVnode: VNode
  86. ) => void;
  87. export interface DirectiveOptions {
  88. bind?: DirectiveFunction;
  89. inserted?: DirectiveFunction;
  90. update?: DirectiveFunction;
  91. componentUpdated?: DirectiveFunction;
  92. unbind?: DirectiveFunction;
  93. }