为什么 Sorbet 认为我在 RBI 文件中为其提供显式签名的方法不存在?

Why does Sorbet think that a method I provided an explicit signature for in an RBI file doesn't exist?

我的一个 classes 依赖于 gem Geokit,它不提供自己的 RBI 文件,也不包含在 sorbet-typed 存储库中。我自己为它手写了几个 RBI 文件,包括我在自己的代码中使用的方法的签名。

当我尝试将依赖于 Geokit 的 class 更改为 typed: true 时,它会抱怨我正在使用的方法不存在。

class 在 typed: false 下类型检查正常。

geokit.rbi

# typed: strong

module Geokit
end

bounds.rbi

# typed: strong

class Geokit::Bounds
    sig do
        params(
            thing: T.any(Geokit::Bounds, T::Array[T.any(T::Array[Numeric], Numeric, String)], String, Geokit::LatLng),
            other: T.nilable(T.any(T::Array[Numeric], String, Geokit::LatLng))
        ).returns(Geokit::Bounds)
    end
    def normalize(thing, other = nil); end
end

lib/platform/x.rb

class X
  BOUNDS = Geokit::Bounds.normalize([[0.8852118e2, -0.751305e1], [0.689324e2, -0.386637e1]])
end

我得到的错误如下:

lib/platform/x.rb:2: Method normalize does not exist on T.class_of(Geokit::Bounds) https://srb.help/7003
     2 |  BOUNDS = Geokit::Bounds.normalize([[0.8852118e2, -0.751305e1], [0.689324e2, -0.386637e1]])
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Autocorrect: Use `-a` to autocorrect
    lib/platform/x.rb:2: Replace with initialize
     2 |  BOUNDS = Geokit::Bounds.normalize([[0.8852118e2, -0.751305e1], [0.689324e2, -0.386637e1]])

您在该方法的 RBI 定义中缺少 self.。 Sorbet 认为 normalizeBounds.

上的实例方法
# typed: strong

class Geokit::Bounds
    sig do
        params(
            thing: T.any(Geokit::Bounds, T::Array[T.any(T::Array[Numeric], Numeric, String)], String, Geokit::LatLng),
            other: T.nilable(T.any(T::Array[Numeric], String, Geokit::LatLng))
        ).returns(Geokit::Bounds)
    end
    def self.normalize(thing, other = nil); end
end