ruby 严格检查在日期时间返回RBS::UnknownTypeName

ykejflvf  于 2023-01-16  发布在  Ruby
关注(0)|答案(1)|浏览(95)

我为ruby代码实现了一个.rbs文件,除了DateTime之外,其他都可以使用。
拼音文件:

class foo
  # other attributes
  attr_reader :bar

  def initialize(bar)
    @bar = bar
  end

end

这是rbs文件:

class Foo
  # other attributes
  attr_reader bar: DateTime

  def initialize: (DateTime bar) -> void

end

但是当我运行steep check时,我得到了以下错误:

path/foo.rbs:14:26: [error] Cannot find type `DateTime`
│ Diagnostic ID: RBS::UnknownTypeName
│
└   attr_reader bar: DateTime

为什么找不到DateTime?是否应使用其他声明?
其余的类型工作正常,无论它们是由我创建的还是基本类型,如IntegerString
谢谢。

uajslkp6

uajslkp61#

您需要显式地将日期标准库类型添加到Steepfile

target :lib do
  signature "sig"
  
  check "lib"

  library "date" # add standard libraries here
end

我没有找到任何好的文档,我通过阅读steep's Steepfile把它拼凑在一起,这是我猜它是如何工作的:

  • ruby自动加载的类型可以通过rbs/steep开箱即用,这些签名在rbs/core中)。
  • 标准库不会自动加载,例如DateTime,除非你在Steepfile中明确声明为library,否则rbs/steep无法使用它们。

相关问题