weapp.d.ts 2.45 KB
Newer Older
李嘉林 committed
1 2
/// <reference types="miniprogram-api-typings" />
export declare namespace Weapp {
程默 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  export interface FormField {
    data: {
      name: string;
      value: any;
    };
  }
  /**
   * relation定义,miniprogram-api-typings缺少this定义
   */
  export interface RelationOption<Instance> {
    /** 目标组件的相对关系 */
    type: 'parent' | 'child' | 'ancestor' | 'descendant';
    /** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
    linked?(
      this: Instance,
      target: WechatMiniprogram.Component.TrivialInstance
    ): void;
    /** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
    linkChanged?(
      this: Instance,
      target: WechatMiniprogram.Component.TrivialInstance
    ): void;
    /** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
    unlinked?(
      this: Instance,
      target: WechatMiniprogram.Component.TrivialInstance
    ): void;
    /** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
    target?: string;
  }
  /**
   * obverser定义,miniprogram-api-typings缺少this定义
   */
  type Observer<Instance, T> = (
    this: Instance,
    newVal: T,
    oldVal: T,
    changedPath: Array<string | number>
  ) => void;
  /**
   * methods定义,miniprogram-api-typings缺少this定义
   */
  export interface MethodOption<Instance> {
    [name: string]: (this: Instance, ...args: any[]) => any;
  }
  export interface ComputedOption<Instance> {
    [name: string]: (this: Instance) => any;
  }
  type PropertyType =
    | StringConstructor
    | NumberConstructor
    | BooleanConstructor
    | ArrayConstructor
    | ObjectConstructor
    | FunctionConstructor
    | null;
  export interface PropertyOption {
    [name: string]:
      | PropertyType
      | PropertyType[]
      | {
          /** 属性类型 */
          type: PropertyType | PropertyType[];
          /** 属性初始值 */
          value?: any;
          /** 属性值被更改时的响应函数 */
          observer?:
            | string
            | Observer<WechatMiniprogram.Component.TrivialInstance, any>;
          /** 属性的类型(可以指定多个) */
          optionalTypes?: PropertyType[];
李嘉林 committed
74
        };
程默 committed
75 76
  }
  export {};
李嘉林 committed
77
}