diff --git a/lib/tapioca/dsl/compilers/grape_endpoints.rb b/lib/tapioca/dsl/compilers/grape_endpoints.rb index 7fb2dbf..b3a0fd5 100644 --- a/lib/tapioca/dsl/compilers/grape_endpoints.rb +++ b/lib/tapioca/dsl/compilers/grape_endpoints.rb @@ -172,16 +172,30 @@ def create_callbacks_methods sig { void } def create_request_response_methods - request_response_methods_module.create_method( + sigs = [ + request_response_methods_module.create_sig( + parameters: { + args: "Symbol", + block: "T.nilable(T.proc.bind(#{EndpointClassName}).params(e: Exception).void)", + }, + return_type: "void", + ), + request_response_methods_module.create_sig( + type_parameters: ["E"], + parameters: { + args: "T::Class[T.all(::Exception, T.type_parameter(:E))]", + block: "T.nilable(T.proc.bind(#{EndpointClassName}).params(e: T.type_parameter(:E)).void)", + }, + return_type: "void", + ), + ] + request_response_methods_module.create_method_with_sigs( "rescue_from", + sigs: sigs, parameters: [ - create_rest_param("args", type: "T.untyped"), - create_block_param( - "block", - type: "T.nilable(T.proc.bind(#{EndpointClassName}).params(e: Exception).void)", - ), + RBI::RestParam.new("args"), + RBI::BlockParam.new("block"), ], - return_type: "void", ) end diff --git a/rbi/grape.rbi b/rbi/grape.rbi index 2b22b05..2bea6e5 100644 --- a/rbi/grape.rbi +++ b/rbi/grape.rbi @@ -51,7 +51,15 @@ module Grape module RequestResponse module ClassMethods - sig { params(args: T.untyped, block: T.proc.bind(Grape::Endpoint).params(e: Exception).void).void } + sig { params(args: Symbol, block: T.nilable(T.proc.bind(Grape::Endpoint).params(e: Exception).void)).void } + sig do + type_parameters(:E) + .params( + args: T::Class[T.all(Exception, T.type_parameter(:E))], + block: T.proc.bind(Grape::Endpoint).params(e: T.type_parameter(:E)).void, + ) + .void + end def rescue_from(*args, &block); end end end diff --git a/spec/tapioca/dsl/compilers/grape_endpoints_spec.rb b/spec/tapioca/dsl/compilers/grape_endpoints_spec.rb index cf0c4a4..98fd914 100644 --- a/spec/tapioca/dsl/compilers/grape_endpoints_spec.rb +++ b/spec/tapioca/dsl/compilers/grape_endpoints_spec.rb @@ -85,7 +85,8 @@ def finally(&block); end end module GeneratedRequestResponseMethods - sig { params(args: T.untyped, block: T.nilable(T.proc.bind(PrivateEndpoint).params(e: Exception).void)).void } + sig { params(args: Symbol, block: T.nilable(T.proc.bind(PrivateEndpoint).params(e: Exception).void)).void } + sig { type_parameters(:E).params(args: T::Class[T.all(::Exception, T.type_parameter(:E))], block: T.nilable(T.proc.bind(PrivateEndpoint).params(e: T.type_parameter(:E)).void)).void } def rescue_from(*args, &block); end end @@ -177,7 +178,8 @@ def finally(&block); end end module GeneratedRequestResponseMethods - sig { params(args: T.untyped, block: T.nilable(T.proc.bind(PrivateEndpoint).params(e: Exception).void)).void } + sig { params(args: Symbol, block: T.nilable(T.proc.bind(PrivateEndpoint).params(e: Exception).void)).void } + sig { type_parameters(:E).params(args: T::Class[T.all(::Exception, T.type_parameter(:E))], block: T.nilable(T.proc.bind(PrivateEndpoint).params(e: T.type_parameter(:E)).void)).void } def rescue_from(*args, &block); end end