Gradual typing for Ruby
open sourceMITself-hostablefree
Steep is a static type checker for Ruby that reads types from RBS, Ruby's own signature language: you declare classes, methods and instance variables in .rbs files under sig/, list what to check in a Steepfile, and run steep check. It doesn't infer types from the Ruby code, so methods need signatures and some code needs inline annotations (@type var, @dynamic), while union types, generics and nil-able types narrow through case and is_a? checks. Signatures for gems come from the community RBS collection, and rbs prototype drafts signatures from existing Ruby, Sorbet RBI files or the running program. It implements the Language Server Protocol (steep langserver) for VS Code, Sublime Text, Vim and Neovim, and ships Rake tasks for CI. Soutaro Matsumoto created it in 2017 and still releases it.
Problems it solves
- add static type checking to a Ruby project using RBS signature files instead of inline annotations
- we already write RBS files for our gem and want a tool that checks the code against them
- find nil errors and wrong method calls in Ruby code before running it
- check that every method declared in our signatures is actually implemented
- type errors and completion in VS Code or Neovim for a Ruby project typed with RBS
- run a Ruby type check as a Rake task in CI and fail on errors
- use community type signatures for the gems in our Gemfile.lock when type-checking
- generate first-draft type signatures from existing Ruby code and refine them by hand
- keep Ruby source files free of type annotations and keep the types in separate files
Features
- type checks Ruby against RBS signatures (steep check)
- Steepfile targets that choose which code and signature directories to check
- union types, generics, nil types and narrowing through case and is_a?
- inline annotations such as @type var and @dynamic
- reports methods declared in signatures but not implemented
- gem signatures through the RBS collection
- Language Server Protocol support (steep langserver), with a VS Code extension
- Rake tasks for check and watch
Limitations
- Doesn't infer types from Ruby code: you declare types in RBS files and add annotations1
Capabilities
| Has a command line tool | plan not known |
|---|---|
| Has official SDKs | plan not known |
Alternatives
The same job
These do what Steep does.
- Sorbet A fast, powerful type checker designed for Ruby
- sorbet_erb Extracts Ruby code from ERB files so you can run Sorbet over them
- sorbet_view Extracts Ruby code from view templates (ERB, etc.) for Sorbet type-checking, with LSP support
