Skip to content
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

Annotate ActionController::Parameters#require #224

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rbi/annotations/actionpack.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class ActionController::Parameters
sig { params(key: T.any(String, Symbol)).returns(T.untyped) }
def [](key); end

sig { params(key: T.any(String, Symbol, T::Array[T.any(String, Symbol)])).returns(T.untyped) }
sig { params(key: T.any(String, Symbol)).returns(ActionController::Parameters) }
sig { params(key: T::Array[T.any(String, Symbol)]).returns(T::Array[ActionController::Parameters]) }
Comment on lines +114 to +115
Copy link
Contributor

@amomchilov amomchilov Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these are correct, because require can return "scalar" values:

params = ActionController::Parameters.new(composite: { a: 1, b: 2 }, scalar: 123)
composite_value, scalar_value = params.require([:composite, :scalar])

p composite_value # ✅ => #<ActionController::Parameters {"a"=>1, "b"=>2} permitted: false>
p scalar_value # ❌ => 123

Tracked in: #231

def require(key); end

# required is an alias of require
Expand Down
Loading