diff --git a/test/behavior.test.ts b/test/behavior.test.ts index 146ef53..e1f0e1f 100644 --- a/test/behavior.test.ts +++ b/test/behavior.test.ts @@ -18,8 +18,8 @@ Behavior({ type: Number, value: 0, observer(newVal, oldVal) { - expectType(newVal) - expectType(oldVal.toExponential()) + expectType(newVal) + expectType(oldVal.toExponential()) }, }, }, diff --git a/test/component.test.ts b/test/component.test.ts index c47f772..5993ec9 100644 --- a/test/component.test.ts +++ b/test/component.test.ts @@ -28,12 +28,13 @@ Component({ }, max: { type: Number, + optionalTypes: [String], value: 0, observer(newVal, oldVal) { - expectType(newVal) - expectType(oldVal) + expectType(newVal) + expectType(oldVal) expectType(this.onMyButtonTap()) - expectType(this.data.max) + expectType(this.data.max) }, }, lastLeaf: { diff --git a/types/wx/lib.wx.component.d.ts b/types/wx/lib.wx.component.d.ts index 79e1b44..05a16b3 100644 --- a/types/wx/lib.wx.component.d.ts +++ b/types/wx/lib.wx.component.d.ts @@ -1,22 +1,22 @@ /*! ***************************************************************************** Copyright (c) 2020 Tencent, Inc. All rights reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************** */ @@ -97,12 +97,12 @@ declare namespace WechatMiniprogram { observer?: | string | (( - newVal: ValueType, - oldVal: ValueType, + newVal: any, + oldVal: any, changedPath: Array, ) => void) /** 属性的类型(可以指定多个) */ - optionalTypes?: ShortProperty[] + optionalTypes?: PropertyType[] } type AllFullProperty = | FullProperty @@ -111,20 +111,15 @@ declare namespace WechatMiniprogram { | FullProperty | FullProperty | FullProperty - type ShortProperty = - | StringConstructor - | NumberConstructor - | BooleanConstructor - | ArrayConstructor - | ObjectConstructor - | null - type AllProperty = AllFullProperty | ShortProperty - type PropertyToData = T extends ShortProperty + type AllProperty = AllFullProperty | PropertyType + type PropertyToData = T extends PropertyType ? ValueType - : FullPropertyToData> - type FullPropertyToData = ValueType< - T['type'] - > + : FullPropertyToData> + type FullPropertyToData = + T['optionalTypes'] extends OptionalTypes + ? ValueType + : ValueType + type OptionalTypes = T[] type PropertyOptionToData

= { [name in keyof P]: PropertyToData }