Skip to content

Commit 2819280

Browse files
fix: to_sorbet_type should not return branded types
1 parent 529b41e commit 2819280

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/finch_api/internal/type/enum.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,14 @@ def coerce(value, state:)
116116
#
117117
# @return [Object]
118118
def to_sorbet_type
119-
case values
119+
types = values.map { FinchAPI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
120+
case types
120121
in []
121122
T.noreturn
122-
in [value, *_]
123-
T.all(FinchAPI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(value), self)
123+
in [type]
124+
type
125+
else
126+
T.any(*types)
124127
end
125128
end
126129

lib/finch_api/internal/type/union.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,14 @@ def dump(value, state:)
216216
#
217217
# @return [Object]
218218
def to_sorbet_type
219-
case (v = variants)
219+
types = variants.map { FinchAPI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
220+
case types
220221
in []
221222
T.noreturn
223+
in [type]
224+
type
222225
else
223-
T.any(*v.map { FinchAPI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) })
226+
T.any(*types)
224227
end
225228
end
226229

lib/finch_api/models.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ module FinchAPI
1111
mod.constants.each do |name|
1212
case mod.const_get(name)
1313
in true | false
14-
mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T.all(T::Boolean, mod) } }
14+
mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T::Boolean } }
1515
mod.define_sorbet_constant!(:OrBoolean) { T.type_alias { T::Boolean } }
1616
in Integer
17-
mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { T.all(Integer, mod) } }
17+
mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { Integer } }
1818
mod.define_sorbet_constant!(:OrInteger) { T.type_alias { Integer } }
1919
in Float
20-
mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { T.all(Float, mod) } }
20+
mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { Float } }
2121
mod.define_sorbet_constant!(:OrFloat) { T.type_alias { Float } }
2222
in Symbol
23-
mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { T.all(Symbol, mod) } }
23+
mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { Symbol } }
2424
mod.define_sorbet_constant!(:OrSymbol) { T.type_alias { T.any(Symbol, String) } }
2525
else
2626
end

0 commit comments

Comments
 (0)