【发布时间】:2018-05-29 10:33:48
【问题描述】:
例如,在这个模块字符串的类型规范中:
@spec validate(String.t) :: {:atom}
这是什么意思?以及如何通过iex进行测试?
** (UndefinedFunctionError) function String.t/0 is undefined or private
(elixir) String.t()
更新
看起来有些人没有看到通过 iex 进行测试的必要性
对于我们其他正在学习长生不老药的人,我们可以这样做:
iex(8)> t String
@type t() :: binary()
@type codepoint() :: t()
@type grapheme() :: t()
@type pattern() :: t() | [t()] | :binary.cp()
iex(9)> t(String)
@type t() :: binary()
@type codepoint() :: t()
@type grapheme() :: t()
@type pattern() :: t() | [t()] | :binary.cp()
也适用于 .t
如果要引用“字符串”类型(由 String 模块中的函数),请改用 String.t/0 类型。
【问题讨论】:
-
它是一个类型,你不需要在这里测试任何东西。
标签: elixir