# How to remove a default from \`dry-types\` custom class attribute?

**URL:** <https://discourse.dry-rb.org/t/how-to-remove-a-default-from-dry-types-custom-class-attribute/1727>\
**Category:** dry-types\
**Created:** [September 9, 2023, 5:22pm UTC](https://discourse.dry-rb.org/t/how-to-remove-a-default-from-dry-types-custom-class-attribute/1727 "2023-09-09T17:22:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexWayfer](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/alexwayfer/32/895_2.png) [@AlexWayfer](https://discourse.dry-rb.org/u/AlexWayfer)\
**Post date:** [September 9, 2023, 5:22pm UTC](https://discourse.dry-rb.org/t/how-to-remove-a-default-from-dry-types-custom-class-attribute/1727/1 "2023-09-09T17:22:44Z")

</div>

Hello.

I’m working on a Ruby gem. Especially its specs.

We have custom `Dry::Types` types. And we’re getting parsed API types for specs.

Attributes of our Ruby types have internal defaults, which external API has no.

How can I remove defaults from them?

Example:

```ruby
class ReplyKeyboardRemove < Base
  attribute? :selective, Types::Bool.default(false)
end

```

Error:

```auto
       expected: #<Dry::Types[Sum<Constrained<Nominal<TrueClass> rule=[type?(TrueClass)]> | Constrained<Nominal<FalseClass> rule=[type?(FalseClass)]>>]>
            got: #<Dry::Types[Default<Sum<Constrained<Nominal<TrueClass> rule=[type?(TrueClass)]> | Constrained<Nominal<FalseClass> rule=[type?(FalseClass)]>> value=false>]>
     
       (compared using ==)

```

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [September 10, 2023, 12:41pm UTC](https://discourse.dry-rb.org/t/how-to-remove-a-default-from-dry-types-custom-class-attribute/1727/2 "2023-09-10T12:41:03Z")

</div>

So I haven’t had to do this myself before, but one thing that’s with noting here is that a type with a default is just a _wrapper_ over the original type, which you can still get to via `my_type.type`.

So something like this becomes possible:

```ruby
Undefined = Dry::Core::Constants::Undefined

t = Types::Bool.default(true)

# Show the default in action
t[Undefined]
# => true

# Get the raw (non-defaulting) type
tt = t.type

# Show it no longer has a default
tt[Undefined]
# This errors as expected!
# => Undefined violates constraints (type?(FalseClass, Undefined) failed) (Dry::Types::ConstraintError)

# And of course it still accepts a valid value
tt[false]
# => false

```

You’ll probably want to be careful with how you construct your types to make sure it’s actually the `Default` wrapper that you’re unwrapping, but hopefully this can set you off in a good direction.

---

<div class="post-metadata">

**Author:** ![AlexWayfer](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/alexwayfer/32/895_2.png) [@AlexWayfer](https://discourse.dry-rb.org/u/AlexWayfer)\
**Post date:** [September 10, 2023, 12:53pm UTC](https://discourse.dry-rb.org/t/how-to-remove-a-default-from-dry-types-custom-class-attribute/1727/3 "2023-09-10T12:53:21Z")

</div>

Yeah, thanks, I’ve already found this work-around yesterday. `attribute.type.type` seems weird, but works. I thought maybe there is a more elegant way. OK.

About safety — yeah, just `if type.default?` enough.
