Skip to content

Commit 62260a5

Browse files
fix: to_sorbet_type should not return branded types
1 parent 993b8ac commit 62260a5

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/onebusaway_sdk/internal/type/enum.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ def coerce(value, state:)
9191
#
9292
# @return [Object]
9393
def to_sorbet_type
94-
case values
94+
types = values.map { OnebusawaySDK::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
95+
case types
9596
in []
9697
T.noreturn
97-
in [value, *_]
98-
T.all(OnebusawaySDK::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(value), self)
98+
in [type]
99+
type
100+
else
101+
T.any(*types)
99102
end
100103
end
101104

lib/onebusaway_sdk/internal/type/union.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,14 @@ def dump(value, state:)
201201
#
202202
# @return [Object]
203203
def to_sorbet_type
204-
case (v = variants)
204+
types = variants.map { OnebusawaySDK::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
205+
case types
205206
in []
206207
T.noreturn
208+
in [type]
209+
type
207210
else
208-
T.any(*v.map { OnebusawaySDK::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) })
211+
T.any(*types)
209212
end
210213
end
211214

lib/onebusaway_sdk/models.rb

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

0 commit comments

Comments
 (0)