From 22eb0fe55cf4b2225fe705fccb555f897b3d57b9 Mon Sep 17 00:00:00 2001 From: lvzl <627417163@qq.com> Date: Thu, 19 Sep 2024 18:56:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20behavior=20data=E3=80=81properties?= =?UTF-8?q?=E3=80=81methods=20=E6=B2=A1=E6=9C=89=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=97=B6=E8=AE=BF=E9=97=AE=E4=B8=BA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E5=B1=9E=E6=80=A7=E4=B8=8D=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- test/issue.test.ts | 36 ++++++++++++++++++++++++++++++++++ types/wx/lib.wx.behavior.d.ts | 6 +++--- types/wx/lib.wx.component.d.ts | 4 ++-- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 24efa08..125a5f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "miniprogram-api-typings", - "version": "3.12.3", + "name": "@mtypes/miniprogram-api-typings", + "version": "4.0.0", "description": "Type definitions for APIs of Wechat Mini Program in TypeScript", "main": "./index.d.ts", "types": "./index.d.ts", diff --git a/test/issue.test.ts b/test/issue.test.ts index a7b0b84..9390d0c 100644 --- a/test/issue.test.ts +++ b/test/issue.test.ts @@ -598,4 +598,40 @@ import WX = WechatMiniprogram }, } }) +} + +{ + const b1 = Behavior({ + methods: { + methodA() { + return [''] + }, + }, + }) + const b2 = Behavior({ + properties: { + pB: { + type: Array, + value: [] as string[], + } + } + }) + const b3 = Behavior({ + data: { + dataC: 'init data', + } + }) + + Component({ + behaviors: [b1, b2, b3], + methods: { + test() { + expectType(this.data.pB) + expectType(this.data.dataC) + expectType(this.methodA()) + expectError(this.data.xxx) + expectError(this.properties.yyy) + }, + } + }) } \ No newline at end of file diff --git a/types/wx/lib.wx.behavior.d.ts b/types/wx/lib.wx.behavior.d.ts index 140259e..22993a9 100644 --- a/types/wx/lib.wx.behavior.d.ts +++ b/types/wx/lib.wx.behavior.d.ts @@ -29,9 +29,9 @@ declare namespace WechatMiniprogram.Behavior { TBehavior extends BehaviorOption = [] > = string & { [key in 'BehaviorType']?: { - data: TData & Component.MixinData - properties: TProperty & Component.MixinProperties - methods: TMethod & Component.MixinMethods + data: Component.FilterUnknownProperty & Component.MixinData + properties: Component.FilterUnknownProperty & Component.MixinProperties + methods: Component.FilterUnknownProperty & Component.MixinMethods } } type Instance< diff --git a/types/wx/lib.wx.component.d.ts b/types/wx/lib.wx.component.d.ts index 3731be8..e2ece75 100644 --- a/types/wx/lib.wx.component.d.ts +++ b/types/wx/lib.wx.component.d.ts @@ -36,10 +36,10 @@ declare namespace WechatMiniprogram.Component { (TIsPage extends true ? Page.ILifetime : {}) & Omit & { /** 组件数据,**包括内部数据和属性值** */ - data: TData & MixinData & + data: FilterUnknownProperty & MixinData & MixinProperties & PropertyOptionToData> /** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */ - properties: TData & MixinData & + properties: FilterUnknownProperty & MixinData & MixinProperties & PropertyOptionToData> } From 535264e8e58d533982300c38f30ebb3f402a81f8 Mon Sep 17 00:00:00 2001 From: lvzl <627417163@qq.com> Date: Fri, 20 Sep 2024 10:28:19 +0800 Subject: [PATCH 2/3] feat: rename --- types/wx/lib.wx.behavior.d.ts | 6 +++--- types/wx/lib.wx.component.d.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/wx/lib.wx.behavior.d.ts b/types/wx/lib.wx.behavior.d.ts index 22993a9..251c0e3 100644 --- a/types/wx/lib.wx.behavior.d.ts +++ b/types/wx/lib.wx.behavior.d.ts @@ -29,9 +29,9 @@ declare namespace WechatMiniprogram.Behavior { TBehavior extends BehaviorOption = [] > = string & { [key in 'BehaviorType']?: { - data: Component.FilterUnknownProperty & Component.MixinData - properties: Component.FilterUnknownProperty & Component.MixinProperties - methods: Component.FilterUnknownProperty & Component.MixinMethods + data: Component.FilterUnknownType & Component.MixinData + properties: Component.FilterUnknownType & Component.MixinProperties + methods: Component.FilterUnknownType & Component.MixinMethods } } type Instance< diff --git a/types/wx/lib.wx.component.d.ts b/types/wx/lib.wx.component.d.ts index e2ece75..3753624 100644 --- a/types/wx/lib.wx.component.d.ts +++ b/types/wx/lib.wx.component.d.ts @@ -21,7 +21,7 @@ SOFTWARE. ***************************************************************************** */ declare namespace WechatMiniprogram.Component { - type FilterUnknownProperty = string extends keyof TProperty ? {} : TProperty + type FilterUnknownType = string extends keyof T ? {} : T type Instance< TData extends DataOption, TProperty extends PropertyOption, @@ -36,11 +36,11 @@ declare namespace WechatMiniprogram.Component { (TIsPage extends true ? Page.ILifetime : {}) & Omit & { /** 组件数据,**包括内部数据和属性值** */ - data: FilterUnknownProperty & MixinData & - MixinProperties & PropertyOptionToData> + data: FilterUnknownType & MixinData & + MixinProperties & PropertyOptionToData> /** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */ - properties: FilterUnknownProperty & MixinData & - MixinProperties & PropertyOptionToData> + properties: FilterUnknownType & MixinData & + MixinProperties & PropertyOptionToData> } type IEmptyArray = [] From b7e6fe5b56fd17a15ca50abd9cfff3556bffa034 Mon Sep 17 00:00:00 2001 From: lvzl <627417163@qq.com> Date: Fri, 20 Sep 2024 10:41:40 +0800 Subject: [PATCH 3/3] revert: package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 125a5f9..24efa08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@mtypes/miniprogram-api-typings", - "version": "4.0.0", + "name": "miniprogram-api-typings", + "version": "3.12.3", "description": "Type definitions for APIs of Wechat Mini Program in TypeScript", "main": "./index.d.ts", "types": "./index.d.ts",