Skip to content

Commit

Permalink
Merge branch 'master' into behavior-ts-support
Browse files Browse the repository at this point in the history
  • Loading branch information
lv-z-l committed Sep 3, 2024
2 parents 40e11c6 + 8a05832 commit 14bb344
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Component({
max: {
type: Number,
value: 0,
observer(newVal: number, oldVal: number) {
observer(newVal, oldVal) {
expectType<number>(newVal)
expectType<number>(oldVal)
expectType<void>(this.onMyButtonTap())
Expand Down
12 changes: 5 additions & 7 deletions types/wx/lib.wx.component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SOFTWARE.
***************************************************************************** */

declare namespace WechatMiniprogram.Component {
type FilterUnknownProperty<TProperty> = string extends keyof TProperty ? {} : TProperty
type Instance<
TData extends DataOption,
TProperty extends PropertyOption,
Expand All @@ -34,12 +35,11 @@ declare namespace WechatMiniprogram.Component {
MixinMethods<TBehavior> &
(TIsPage extends true ? Page.ILifetime : {}) &
Omit<TCustomInstanceProperty, 'properties' | 'methods' | 'data'> & {
/** 组件数据,**包括内部数据和属性值** */
data: TData & MixinData<TBehavior> &
MixinProperties<TBehavior> & PropertyOptionToData<TProperty>
MixinProperties<TBehavior> & PropertyOptionToData<FilterUnknownProperty<TProperty>>
/** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
properties: TData & MixinData<TBehavior> &
MixinProperties<TBehavior> & PropertyOptionToData<TProperty>
MixinProperties<TBehavior> & PropertyOptionToData<FilterUnknownProperty<TProperty>>
}

type IAnyArray = []
Expand Down Expand Up @@ -79,10 +79,8 @@ declare namespace WechatMiniprogram.Component {
interface Constructor {
<
TData extends DataOption,
// 给泛型默认值,避免出现当组件无 properties 选项时
// 当xxx未在 data 中声明,this.data.xxx 为 any 且不报 TS2339 error 的问题。
TProperty extends PropertyOption = {},
TMethod extends MethodOption = {},
TProperty extends PropertyOption,
TMethod extends MethodOption,
TBehavior extends BehaviorOption = [],
TCustomInstanceProperty extends IAnyObject = {},
TIsPage extends boolean = false
Expand Down

0 comments on commit 14bb344

Please sign in to comment.