Access default value in the type AST

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.

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

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!

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

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"