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)) }