# Is there a way to have Elixir Records without default values?

**URL:** <https://forum.devtalk.com/t/is-there-a-way-to-have-elixir-records-without-default-values/46210>\
**Category:** Backend Questions/Help\
**Tags:** elixir\
**Created:** [22 March 2022 10:51 UTC](https://forum.devtalk.com/t/is-there-a-way-to-have-elixir-records-without-default-values/46210 "2022-03-22T10:51:36Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Fl4m3Ph03n1x](https://forum.devtalk.com/user_avatar/forum.devtalk.com/fl4m3ph03n1x/32/3808_2.png) [@Fl4m3Ph03n1x](https://forum.devtalk.com/u/Fl4m3Ph03n1x)\
**Post date:** [6 April 2022 13:38 UTC](https://forum.devtalk.com/t/is-there-a-way-to-have-elixir-records-without-default-values/46210/4 "2022-04-06T13:38:59Z")

</div>

## Answer

1. Is there a way to have Records not accept default values?

No. This is not possible with Records. Records were never intended for this use case and forcing this abstraction into them would only complicate things. While one could use a wrapper `new` method, it would still be a lot of boilerplate and all the validation for type would be on the user.

1. At the time of this writing, there are none. However, in another post I created a macro that achieves this purpose: [How to define Macro for a new Type? - #10 by Fl4m3Ph03n1x - Questions / Help - Elixir Programming Language Forum](https://elixirforum.com/t/how-to-define-macro-for-a-new-type/46852/10?u=fl4m3ph03n1x)

In that post I propose an API and then I refine it with the community’s help. For those of you who are curious, it can be used like this:

**type.ex**

```auto
defmodule Type do
  import NewType

  deftype(Name, String.t())
end

```

**test.ex**

```auto
defmodule Test do
  alias Type.Name

  @spec print(Name.t()) :: binary
  def print(name), do: Name.extract(name)

  def run_1 do
    # dialyzer complains !
    Name.new(1)
  end

  def run_2 do
    # dialyzer complains !
    print("john")
  end

  @spec run_3 :: binary
  def run_3 do
    print(Name.new("dow"))
  end
end

```

---

_[View the full topic](https://forum.devtalk.com/t/is-there-a-way-to-have-elixir-records-without-default-values/46210)._
