feat: 优化FilterUnknownType工具类#351
Merged
SgLy merged 5 commits intoJun 12, 2025
Merged
Conversation
Member
|
能同时在 |
Contributor
Author
Done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改进
FilterUnknownType<T>类型定义的精确性🔍 问题描述
原来的
FilterUnknownType<T>实现过于粗暴:当类型
T包含字符串索引签名时,会直接返回空对象{},这导致所有已知的字面量属性也被过滤掉了。✨ 解决方案
新的实现更加精确:
这个实现会:
T的每个属性键Pstring extends P为true),将其过滤为neverT[P]🎯 改进效果
以一个混合类型为例:
💡 意义
新实现能够精确地只过滤掉未知的动态属性,同时保留所有已知的字面量属性,这对于微信小程序组件的类型安全更加重要,确保开发者能够正确访问到组件的已知属性,而不会因为存在字符串索引签名就丢失所有类型信息。