-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用typebox的default代替exampleProperties #584
Comments
很不错,我们确实打算这样替换。一开始用exampleProperties是个临时方案,当时不知道typebox有这个用法。 |
我觉得 default value 和 default value 可能用于某些场景下将属性处理为默认值,比如新增数组项、表达式转换为普通值等。
|
如果你们暂时没有规划的话,可以建个PR一起来贡献代码 |
我理解你的说法,但其实是可以等价的,我这里举个例子:
比如这个,当我解析的时候,我认为 users 的默认值是:
当我新增一个用户的时候,默认值是:
这应该和你说的不矛盾吧 |
@MrWindlike 说的有道理。理论上来说,exampleProperties 和 default value 确实可以不同。exampleProperties 可能会为了展示效果更佳复杂花哨一点,而default value应该是尽量简洁的。 但是我们目前有个函数 而且exampleProperties目前只是针对component的properties的,但是实际上所有用Typebox声明的地方都有这个需求。比如component的 state、trait的property和state,还有method的parameters等等 所以,我觉得把 exampleProperties 还是应该放到 defaultValue 中,但是全面替换这个有一定工作量。 |
default value 的语义应该是程序处理上的默认值?example 就比较灵活一些,可以是希望给用户呈现的功能示例。 比如一个日历组件,有一个 events props 用于描述日历上的事项,程序的处理可能希望 default value 是空数组,保证用户不传入时类型也始终一致;example values 可能希望程序一组事项,用于 demo 这个功能。 |
我整理下来sunmao现在其实有两个问题是需要解决的:
所以结论可能是exampleProperties还是需要保留的,但是default Value也需要加,两者功能不同。 |
What problem does this feature solve?
使用typebox的default代替exampleProperties
原来是这样:
现在是这样:
进一步收敛
The text was updated successfully, but these errors were encountered: