AaronC81 / sord

Convert YARD docs to Sorbet RBI and Ruby 3/Steep RBS files
https://sord.aaronc.cc
MIT License
293 stars 18 forks source link

Support defining Type Unions in Hash key or value signatures #150

Open postmodern opened 1 year ago

postmodern commented 1 year ago

Is your feature request related to a problem? Please describe.

I am trying to use sord-4.0.0 to parse a very thoroughly YARD documented library of mine, but noticed that it does not recognize Type Unions within the key or value part of a Hash{K => V} signature.

Describe the solution you'd like

sord should be able to parse the following Hash{...} type signatures:

Describe alternatives you've considered

The obvious workaround is to change the YARD Hash{...} type signature to Hash{KeyType1 => Value}, Hash{KeyType2 => Value}, however this implies that all of the Hash'es keys are either of KeyType or of KeyType2, but never a mixture of the two key types. I could change the Hash{...} signature to Hash{Object => ValueType} but that makes the Hash type signature less descriptive. In my library KeyType1 and KeyType2 do not have a common base class, so that is also not an option.

Additional context

real world code