From 2951ab4f28e5671063a9e9d05c48e760edf999a7 Mon Sep 17 00:00:00 2001 From: Gabor Szakacs Date: Sat, 30 Jul 2022 17:36:12 +0200 Subject: [PATCH 1/2] Make ActiveRecord#find return value typed --- lib/tapioca/dsl/compilers/active_record_relations.rb | 2 +- spec/tapioca/dsl/compilers/active_record_relations_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tapioca/dsl/compilers/active_record_relations.rb b/lib/tapioca/dsl/compilers/active_record_relations.rb index 676d38274..e026626e5 100644 --- a/lib/tapioca/dsl/compilers/active_record_relations.rb +++ b/lib/tapioca/dsl/compilers/active_record_relations.rb @@ -522,7 +522,7 @@ def create_common_methods(common_relation_methods_module) parameters: [ create_rest_param("args", type: "T.untyped"), ], - return_type: "T.untyped" + return_type: "T.any(#{constant_name}, T::Array[#{constant_name}])" ) when :find_by create_common_method( diff --git a/spec/tapioca/dsl/compilers/active_record_relations_spec.rb b/spec/tapioca/dsl/compilers/active_record_relations_spec.rb index ba181c4bf..ac4a924b6 100644 --- a/spec/tapioca/dsl/compilers/active_record_relations_spec.rb +++ b/spec/tapioca/dsl/compilers/active_record_relations_spec.rb @@ -93,7 +93,7 @@ def fifth; end sig { returns(::Post) } def fifth!; end - sig { params(args: T.untyped).returns(T.untyped) } + sig { params(args: T.untyped).returns(T.any(::Post, T::Array[::Post])) } def find(*args); end sig { params(args: T.untyped).returns(T.nilable(::Post)) } From 77bcc69af254bea19aa2a8f199fadcbb519f18b3 Mon Sep 17 00:00:00 2001 From: Gabor Szakacs Date: Sat, 30 Jul 2022 19:15:44 +0200 Subject: [PATCH 2/2] Empty commit to trigger new build