# Access default value in the type AST

**URL:** <https://discourse.dry-rb.org/t/access-default-value-in-the-type-ast/1789>\
**Category:** dry-types\
**Created:** [April 2, 2024, 1:41pm UTC](https://discourse.dry-rb.org/t/access-default-value-in-the-type-ast/1789 "2024-04-02T13:41:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elcuervo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/elcuervo/32/900_2.png) [@elcuervo](https://discourse.dry-rb.org/u/elcuervo)\
**Post date:** [April 2, 2024, 1:41pm UTC](https://discourse.dry-rb.org/t/access-default-value-in-the-type-ast/1789/1 "2024-04-02T13:41:24Z")

</div>

Hello!  
I wonder if there’s a way to access the default value of a type while parsing the AST.  
I’m building a gem to translate types into other structures and having the default value would help.

```ruby
Types::String.default("test".freeze).to_ast
# => [:constrained, [[:nominal, [String, {}]], [:predicate, [:type?, [[:type, String], [:input, Undefined]]]]]]

```

---

<div class="post-metadata">

**Author:** ![mbajur](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/mbajur/32/945_2.png) [@mbajur](https://discourse.dry-rb.org/u/mbajur)\
**Post date:** [June 24, 2024, 9:31pm UTC](https://discourse.dry-rb.org/t/access-default-value-in-the-type-ast/1789/2 "2024-06-24T21:31:05Z")

</div>

I second that - it would be great to know what (if any) default value is defined for given type. In my case, it’s as simple as being able to tell if it’s defined or not but getting the actual value might be handy as well. Thanks!

---

<div class="post-metadata">

**Author:** ![elcuervo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/elcuervo/32/900_2.png) [@elcuervo](https://discourse.dry-rb.org/u/elcuervo)\
**Post date:** [July 5, 2024, 2:07pm UTC](https://discourse.dry-rb.org/t/access-default-value-in-the-type-ast/1789/3 "2024-07-05T14:07:02Z")

</div>

If you want just the default value for a given type you can do something like:

```ruby
other_type = Types::String
other_type.default?
# => false
other_type.value
# NoMethodError: undefined method `value' ...

test_type = Types::String.default("test")
test_type.default?
# => true
test_type.value
# => "test"

```
