Generates or updates Sorbet type signatures in separate .rbi files. Triggers when creating, updating, or maintaining type signatures for Ruby source files.
Generate or update Sorbet type signatures in separate .rbi files. Supports both full generation from scratch and partial updates for individual changed files. RBI files are used when you cannot or should not modify the original Ruby source - such as for gems, generated code, or legacy codebases.
When generating Sorbet RBI signatures, always follow these steps.
Copy this checklist and track your progress:
Sorbet RBI Generation Progress:
- [ ] Step 1: Analyze the Ruby source
- [ ] Step 2: Generate RBI files
- [ ] Step 3: Eliminate `T.untyped` in signatures
- [ ] Step 4: Review and refine signatures
- [ ] Step 5: Validate signatures with Sorbet
T.untyped. Infer the proper type instead.T.unsafe - it bypasses type checking entirely.T.cast - it forces types without verification.bundle exec if the project has Gemfile.sig { } block syntax for method signatures.extend T::Sig to classes/modules before using sig../rbi directory.When processing multiple Ruby files, create a tracking file to ensure all files are covered:
Create tracking file .sorbet-rbi-generation-todo.tmp:
[ ] app/models/user.rb
[ ] app/models/post.rb
[ ] app/services/auth_service.rb
Process files one by one:
[ ] entry[x]Cleanup: Remove the tracking file after all files are processed:
rm .sorbet-rbi-generation-todo.tmp
If interrupted, the tracking file allows resuming from where you left off.
Always perform this step.
Read and understand the Ruby source file:
public, private, protected.Always perform this step.
Determine the correct RBI directory:
Place RBI files in ./rbi directory. Sorbet reads all .rbi files from this location.
RBI files are needed to describe code Sorbet cannot understand statically:
define_method or method_missingconst_get/const_setextendCreate the RBI file with typed sigil:
# typed: strict
Add extend T::Sig to each class/module:
class MyClass
extend T::Sig
end
Add method stubs with signatures (no method bodies):
Example - Ruby Source:
class User
attr_reader :name, :age
def initialize(name, age)
@name = name
@age = age
end
def greet(greeting)
"#{greeting}, #{@name}!"
end
end
Example - RBI File (rbi/user.rbi):
# typed: strict
class User
extend T::Sig
sig { returns(String) }
attr_reader :name
sig { returns(Integer) }
attr_reader :age
sig { params(name: String, age: Integer).void }
def initialize(name, age); end
sig { params(greeting: String).returns(String) }
def greet(greeting); end
end
T.untyped in SignaturesAlways perform this step.
T.untyped with proper types.T.untyped only as a last resort when type cannot be determined.Always perform this step.
T.untyped types.Always perform this step.
Run Sorbet type checker to validate signatures:
srb tc
Or with bundle:
bundle exec srb tc
This checks:
Fix any errors reported and repeat until validation passes.