RBI: getter methods on belongs_to associations have returns(T.nilable(...)) as sig but belongs_to reflection is not optional
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- ruby
调研方向
从 Tapioca::Dsl::Compilers::ActiveRecordAssociations#populate_single_assoc_getter_setter 开始,检查 belongs_to 的 reflection 选项如何决定生成的 getter 返回类型。比较可选和非可选 belongs_to 关联生成的 RBI,然后验证只有非可选情况避免了 nilable 类型标注。
由索引模型根据 Issue 内容生成。
描述
I noticed the returns signature of any belongs_to association on a model is always nilable in the RBI file, even if the belongs_to is not optional. Rails will raise an error if a nil value is present for such an association. I don't find it optimal to add T.must everywhere to change this in application code.
I changed Tapioca::Dsl::Compilers::ActiveRecordAssociations#populate_single_assoc_getter_setter and it seems to work:
association_type = if !reflection.options[:optional] && reflection.is_a?(ActiveRecord::Reflection::BelongsToReflection)
association_class
else
as_nilable_type(association_class)
end
What do you think ?
- 主要语言
- Ruby
- 星标
- 874
- 派生
- 167
- 平均合并
- 5 天 12 小时
- 30 天内合并 PR
- 11
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Shopify/tapioca 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
Shopify/tapioca#2662 · 1 条评论 ·
维护者通常 4 天内回复
-
Option to omit private methods from gem RBIs, with a per-gem opt-in可能已有人在做 @efegokdemir 于 3 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 30/100
维护者通常 4 天内回复
-
难度 3/5 1-2 天 新手友好度 57/100
维护者通常 4 天内回复
-
Improve `check-shims` performance可能已有人在做 @KaanOzkan 于 18 天前认领。 未关闭
Shopify/tapioca#2728 · 已指派 1 人 ·
维护者通常 4 天内回复
-
难度 5/5 一周以上 新手友好度 30/100
维护者通常 4 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
thewca/worldcubeassociation.org#16088 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
Homebrew/homebrew-core#319232 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
enhancement help wanted
难度 2/5 1-3 小时 新手友好度 78/100
ecosyste-ms/repos#1215 ·
维护者通常 1 天内回复