Skip to content

Resulted RBS are invalid #51

@developer88

Description

@developer88

While trying to test your gem I found several issues.

Here is example trb file:

require "httparty"
require "json"
require "time"

class RubyVersion
  API_URL = "https://api.github.com/repos/ruby/ruby/releases/latest"

  class Response
    attr_reader :code
    attr_reader :json

    def initialize(code: Integer, json: Hash<String, untyped>)
      @code = code
      @json = json
    end

    def success?
      (200..299).include?(@code)
    end
  end


  def fetch_response
    http = HTTParty.get(API_URL, headers: { 'User-Agent' => 'static-typing-demo' })
    Response.new(http.code.to_i, JSON.parse(http.body))
  end

  def self.fetch(printer)
    resp = new.fetch_response
    raise "HTTP #{resp.code}" unless (200..299).include?(resp.code)
    data = resp.json
    published = Time.parse((data['published_at'] || Time.now.utc.iso8601).to_s)
    printer.call((data['tag_name'] || data['name']).to_s, data['html_url'], published)
  end
end

If run trc src/file.trb it produces:

class RubyVersion
  @code: Integer
  @json: Hash[String, untyped]

  def initialize: (code: Integer, json: Hash[String, untyped]) -> void
  def success?: () -> nil
  def fetch_response: () -> nil
end

which is completely incorrect.

When trying to specify result type for RubyVersion::Response.success? as boolean it complaints that the inferred type is nil and I could not find the way to specify what I need.

I am using ruby 4.0 with your lates version 0.0.46

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions