带有 class 参数的函数的 Sorbet 签名?

Sorbet signature for a function with class argument?

如何为以下 archive_all 函数编写签名?

sorbet.run

# typed: true
extend T::Sig

module Archivable
  def archive
  end
end
class Book
  extend Archivable
end
class Magazine
  extend Archivable
end

sig {params(klass: T.class_of(Archivable)).void}
def archive_all(klass)
  klass.archive
end

archive_all(Book) 
archive_all(Magazine)

冰糕错误:

editor.rb:17: Method archive does not exist on T.class_of(Archivable) https://srb.help/7003
    17 |  klass.archive
          ^^^^^^^^^^^^^
    editor.rb:5: Did you mean: Archivable#archive?
     5 |  def archive
          ^^^^^^^^^^^

您希望能够传递 Archivable 的任何实例。正确的做法是使用 Sorbet 的一项功能,称为 class type:

sig {params(klass: Archivable).void}

Observe.