Open
Description
Problem
With the generated types for enums it's tricky to figure out what the possible variants are without spelunking through .proto files or other usages in the codebase.
For example, with the following enum:
enum Mode {
INVALID_MODE = 0;
LIVEMODE = 1;
TESTMODE = 2;
}
the generated .rbi doesn't help when figuring out the possible variants:
class Common::Feature < ::Google::Protobuf::AbstractMessage
sig do
params(
mode: T.nilable(T.any(Symbol, String, Integer)),
).void
end
def initialize(
mode: :INVALID_MODE,
)
end
sig { returns(Symbol) }
def mode
end
sig { params(value: T.any(Symbol, String, Integer)).void }
def mode=(value)
end
end
relevant generator code:
Ideas
Add a comment with the Symbol variants:
# variants: :INVALID_MODE, :LIVEMODE, :TESTMODE
sig { params(value: T.any(Symbol, String, Integer)).void }
def mode=(value)
end
somehow express the union in the type itself
but also keep the more general Symbol
type since other variants could be passed in
not sure about this one
Metadata
Metadata
Assignees
Labels
No labels