-
Notifications
You must be signed in to change notification settings - Fork 229
Release Note 3.5
Some of the highlights in RBS 3.5 are:
- Optional record keys (#1717, #1732)
- Untyped function parameters (#1806)
- Add lexer API (#1829, #1831)
You can install it with $ gem install rbs or using Bundler.
gem 'rbs', '~> 3.5.0.pre'Read the CHANGELOG for the details.
Warning
- RBS 3.5 has many stdlib signature updates. Updating to 3.5 may cause having different type checking results.
- Using new syntax may cause issues with tools that doesn't support RBS 3.5
The record keys with ? prefix are optional.
type json = {
?id: Integer,
name: String,
email: String?
}As you can see in types.rbs, the Types::Record type provides three methods.
class RBS::Types::Record
attr_reader all_fields: Hash[Symbol, [t, bool]]
attr_reader fields: Hash[Symbol, t]
attr_reader optional_fields: Hash[Symbol, t]
endThe #fields only contains required fields, and optional_fields contains optional fields. It means the existing RBS based tools continue working but ignores optional fields.
Pull Requests: #1806
Method type parameters and block parameters can be untyped with (?) syntax.
class Foo
def dynamic: (?) -> void
end
class ActiveRecord::Base
def self.scope: (Symbol) { (?) -> void } -> void
| (Symbol, ^(?) -> void) -> void
endParser.lex method returns the list of tokens from the input, without constructing syntax tree.
tokens = RBS::Parser.lex(source)The tokens contains all tokens from the source code, including comments and trivia tokens.
You can use the API to implement linters or something that works on comments.