options.d.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { Vue } from './vue';
  2. type Constructor = {
  3. new (...args: any[]): any;
  4. };
  5. type Dictionary<T> = {
  6. [key: string]: T;
  7. };
  8. export type Component = ComponentOptions<Vue> | typeof Vue;
  9. export type AsyncComponent = (
  10. resolve: (component: Component) => void,
  11. reject: (reason?: any) => void
  12. ) => Promise<Component> | Component | void;
  13. export interface ComponentOptions<V extends Vue> {
  14. data?: Dictionary<any> | ((this: V) => Dictionary<any>);
  15. props?: string[] | Dictionary<PropOptions | Constructor | Constructor[]>;
  16. propsData?: Dictionary<any>;
  17. computed?: Dictionary<((this: V) => any) | ComputedOptions<V>>;
  18. methods?: Dictionary<(this: V, ...args: any[]) => any>;
  19. watch?: Dictionary<({ handler: WatchHandler<V> } & WatchOptions) | WatchHandler<V> | string>;
  20. el?: string | HTMLElement | (() => HTMLElement);
  21. template?: string;
  22. replace?: boolean;
  23. init?(this: V): void;
  24. created?(this: V): void;
  25. beforeCompile?(this: V): void;
  26. compiled?(this: V): void;
  27. activate?(this: V, done: () => void): void;
  28. ready?(this: V): void;
  29. attached?(this: V): void;
  30. detached?(this: V): void;
  31. beforeDestroy?(this: V): void;
  32. destroyed?(this: V): void;
  33. directives?: Dictionary<DirectiveOptions<V> | DirectiveFunction<V>>;
  34. elementDirectives?: Dictionary<DirectiveOptions<V> | Function>;
  35. filters?: Dictionary<Function | FilterOptions>;
  36. components?: Dictionary<Component | AsyncComponent>;
  37. transitions?: Dictionary<TransitionOptions>;
  38. partials?: Dictionary<string>;
  39. parent?: Vue;
  40. events?: Dictionary<((...args: any[]) => (boolean | void)) | string>;
  41. mixins?: (ComponentOptions<Vue> | typeof Vue)[];
  42. name?: string;
  43. }
  44. export interface PropOptions {
  45. type?: Constructor | Constructor[] | null;
  46. required?: boolean;
  47. default?: any;
  48. twoWay?: boolean;
  49. validator?(value: any): boolean;
  50. coerce?(value: any): any;
  51. }
  52. export interface ComputedOptions<V extends Vue> {
  53. get?(this: V): any;
  54. set(this: V, value: any): void;
  55. }
  56. export type WatchHandler<V> = (this: V, val: any, oldVal: any) => void;
  57. export interface WatchOptions {
  58. deep?: boolean;
  59. immediate?: boolean;
  60. }
  61. export interface DirectiveInstance<V extends Vue> {
  62. el: HTMLElement;
  63. vm: V;
  64. expression: string;
  65. arg?: string;
  66. name: string;
  67. modifiers: Dictionary<boolean>;
  68. descriptor: any;
  69. params?: Dictionary<any>;
  70. }
  71. export type DirectiveFunction<V extends Vue> = (this: DirectiveInstance<V>, newVal: any, oldVal: any) => void;
  72. export interface DirectiveOptions<V extends Vue> {
  73. bind?(this: DirectiveInstance<V>): void;
  74. update?(this: DirectiveInstance<V>, newVal: any, oldVal: any): void;
  75. unbind?(this: DirectiveInstance<V>): void;
  76. params?: string[];
  77. deep?: boolean;
  78. twoWay?: boolean;
  79. acceptStatement?: boolean;
  80. terminal?: boolean;
  81. priority?: number;
  82. }
  83. export interface FilterOptions {
  84. read?: Function;
  85. write?: Function;
  86. }
  87. export interface TransitionOptions {
  88. css?: boolean;
  89. animation?: string;
  90. enterClass?: string;
  91. leaveClass?: string;
  92. beforeEnter?(el: HTMLElement): void;
  93. enter?(el: HTMLElement, done: () => void): void;
  94. afterEnter?(el: HTMLElement): void;
  95. enterCancelled?(el: HTMLElement): void;
  96. beforeLeave?(el: HTMLElement): void;
  97. leave?(el: HTMLElement, done: () => void): void;
  98. afterLeave?(el: HTMLElement): void;
  99. leaveCancelled?(el: HTMLElement): void;
  100. stagger?(index: number): number;
  101. enterStagger?(index: number): number;
  102. leaveStagger?(index: number): number;
  103. }