wechat-miniprogram / wechat-miniprogram/computed
computed 中定义的属性相互引用时丢失类型提示
Open
@LastLeaf is already working on this.
Since Oct 18, 2024.
- Dominant language
- TypeScript
- Stars
- 696
- Forks
- 61
- PR merge metrics
- No merged PRs in 30d
Description
当前存在的问题
ComponentWithComputed({
computed: {
a(data){
return true
},
b(data){
return data.a
}
}
})
键入 data. 之后并没有 a 属性
原因
当前泛型反推的是整个 TComputed 类型,而 TComputed 的值为 Record<string,xxx>,所以 computed 属性的 key 类型丢失了。
解决办法
把 TCompouted 改为 TComputedKey 反推定义的 key 值:
export const ComponentWithComputed = _ComponentWithComputed as <
TData extends WechatMiniprogram.Component.DataOption,
TProperty extends WechatMiniprogram.Component.PropertyOption,
TMethod extends WechatMiniprogram.Component.MethodOption,
TWatch extends Record<string, (...args: any[]) => void>,
TBehavior extends WechatMiniprogram.Component.BehaviorOption,
TComputedKey extends string,
TCustomInstanceProperty extends
WechatMiniprogram.IAnyObject = WechatMiniprogram.IAnyObject
>(
options: ComputedOptions<
TData,
TProperty,
TMethod,
TWatch,
TBehavior,
TComputedKey,
Record<
TComputedKey,
(
data: TData & {
[key in keyof TProperty]: TProperty[key] extends null
? any
: TProperty[key]
} & { [key in TComputedKey] }
) => any
>,
TCustomInstanceProperty
>
) => string
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.