sig { params(source: T.any(String, Zlib::GzipReader)).returns(T::Boolean) }
def file?(source)
source.is_a?(String) && File.exist?(source.to_s)
end
产生以下错误:
Malformed type declaration. Generic class without type arguments Zlib::GzipReader https://srb.help/5045
的显示类型是
Zlib::GzipReader[T.anything]
但是如果我指定我会得到一个不同的错误:
Method [] does not exist on T.class_of(Zlib::GzipReader)[Zlib::GzipReader[T.anything]] https://srb.help/7003
我认为这是zlib.rbi
中的
相关行,它与协方差有关,但我不确定如何使其发挥作用。
这与促使此 PR 上游进入 Sorbet 的根本原因相同:https://github.com/sorbet/sorbet/pull/6324
我认为你可以打开一个类似的 PR 将
Zlib::GzipReader
的类型变量修复为 T.untyped
(甚至可能是 String
,因为 Zlib::GzipReader#each
似乎会为所提供的块生成字符串实例)。