簡體   English   中英

為什么 Sorbet 認為我在 RBI 文件中提供顯式簽名的方法不存在?

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

我的一個課程依賴於 gem Geokit,它不提供自己的 RBI 文件,也不包含在sorbet-typed repo 中。 我自己為它手寫了幾個 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

庫/平台/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]])

你缺少self. 在該方法的 RBI 定義中。 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM