From 6d0e9e718ca7d254a6b2ad1ccb20bde79d7b169d Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Fri, 31 Aug 2018 15:02:32 +0800 Subject: [PATCH] adding options --- types/weixin-app/index.d.ts | 62 +++++++++++++++------------- types/weixin-app/weixin-app-tests.ts | 5 +++ 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/types/weixin-app/index.d.ts b/types/weixin-app/index.d.ts index 4c331a4f5a..9f6fee5a55 100644 --- a/types/weixin-app/index.d.ts +++ b/types/weixin-app/index.d.ts @@ -3327,19 +3327,16 @@ type ExtendedComponent< Instance extends Component, Data, Methods, - Options, Props -> = CombinedInstance & - Component; +> = CombinedInstance & Component; // CombinedInstance models the `this`, i.e. instance type for (user defined) component type CombinedInstance< Instance extends Component, Data, Methods, - Options, Props -> = Methods & Options & Instance; +> = Methods & Instance; type Prop = (() => T) | { new (...args: any[]): T & object }; @@ -3368,11 +3365,10 @@ type ThisTypedComponentOptionsWithRecordProps< V extends Component, Data, Methods, - Options, Props > = object & - ComponentOptions Data), Methods, Options, Props> & - ThisType>>; + ComponentOptions Data), Methods, Props> & + ThisType>>; interface ComponentRelation { /** 目标组件的相对关系,可选的值为 parent 、 child 、 ancestor 、 descendant */ @@ -3432,7 +3428,6 @@ interface ComponentOptions< Instance extends Component, Data = DefaultData, Methods = DefaultMethods, - Options = object, Props = PropsDefinition > extends Partial { /** @@ -3457,7 +3452,30 @@ interface ComponentOptions< /** * 一些组件选项,请参见文档其他部分的说明 */ - options?: Options; + options?: Partial<{ + /** + * 使用外部样式类可以让组件使用指定的组件外样式类,如果希望组件外样式类能够完全影响组件内部, + * 可以将组件构造器中的options.addGlobalClass字段置为true。这个特性从小程序基础库版本 2.2.3 开始支持。 + * + * @version 2.2.3 + */ + addGlobalClass: boolean; + /** + * 在组件的wxml中可以包含 slot 节点,用于承载组件使用者提供的wxml结构。 + * 默认情况下,一个组件的wxml中只能有一个slot。需要使用多slot时,可以在组件js中声明启用。 + */ + multipleSlots: boolean; + }>; + + /** + * 组件接受的外部样式类,参见 外部样式类 + * + * 有时,组件希望接受外部传入的样式类(类似于 view 组件的 hover-class 属性)。 + * 此时可以在 Component 中用 externalClasses 定义段定义若干个外部样式类。这个特性从小程序基础库版本 1.9.90 开始支持。 + * + * @version 1.9.90 + */ + externalClasses?: string[]; /** * 类似于mixins和traits的组件间代码复用机制 @@ -3582,15 +3600,9 @@ interface Component { */ getRelationNodes(relationKey: string): ComponentRelation[]; } -declare function Component( - options?: ThisTypedComponentOptionsWithRecordProps< - Component, - D, - M, - O, - P - > -): ExtendedComponent, D, M, O, P>; +declare function Component( + options?: ThisTypedComponentOptionsWithRecordProps, D, M, P> +): ExtendedComponent, D, M, P>; /** * behaviors 是用于组件间代码共享的特性 * 类似于一些编程语言中的“mixins”或“traits” @@ -3599,15 +3611,9 @@ declare function Component( * 每个组件可以引用多个 behavior * behavior 也可以引用其他 behavior */ -declare function Behavior( - options?: ThisTypedComponentOptionsWithRecordProps< - Component, - D, - M, - O, - P - > -): ExtendedComponent, D, M, O, P>; +declare function Behavior( + options?: ThisTypedComponentOptionsWithRecordProps, D, M, P> +): ExtendedComponent, D, M, P>; // #endregion // #region Page interface PageShareAppMessageOptions { diff --git a/types/weixin-app/weixin-app-tests.ts b/types/weixin-app/weixin-app-tests.ts index f06ad07336..dea53308d0 100644 --- a/types/weixin-app/weixin-app-tests.ts +++ b/types/weixin-app/weixin-app-tests.ts @@ -29,6 +29,11 @@ let behavior = Behavior({ Component({ behaviors: [behavior, "wx://form-field"], + options: { + multipleSlots: false, + addGlobalClass: false + }, + properties: { myProperty: { // 属性名