Skip to content

Commit

Permalink
Explain keyword spec syntax in typespecs reference (#13553)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara committed May 12, 2024
1 parent 67983c0 commit 1fec26d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/elixir/lib/regex.ex
Expand Up @@ -748,7 +748,7 @@ defmodule Regex do
"Abcadc"
"""
@spec replace(t, String.t(), String.t() | (... -> String.t()), [{:global, boolean()}]) ::
@spec replace(t, String.t(), String.t() | (... -> String.t()), global: boolean()) ::
String.t()
def replace(%Regex{} = regex, string, replacement, options \\ [])
when is_binary(string) and is_list(options) do
Expand Down
8 changes: 8 additions & 0 deletions lib/elixir/pages/references/typespecs.md
Expand Up @@ -200,6 +200,14 @@ def start_link(opts) do
end
```

The following spec syntaxes are equivalent:

```elixir
@type options [{:name, String.t} | {:max, pos_integer} | {:min, pos_integer}]

@type options [name: String.t, max: pos_integer, min: pos_integer]
```

### User-defined types

The `@type`, `@typep`, and `@opaque` module attributes can be used to define new types:
Expand Down

0 comments on commit 1fec26d

Please sign in to comment.