我的一个课程依赖于 gem Geokit,它不提供自己的 RBI 文件,也不包含在sorbet-typed
repo 中。我自己为它手写了几个 RBI 文件,包括我在自己的代码中使用的方法的签名。
当我尝试将依赖 Geokit 的类更改为 时typed: true
,它抱怨我使用的方法不存在。
类类型检查在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]])