options.d.ts 3.1 KB

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