Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support T.any for deserialization #107

Merged
merged 2 commits into from
Jul 5, 2024

Conversation

antoinesaliba
Copy link
Collaborator

Since my other PR was so quickly replaced, had to find something else to contribute 😉

If you've got a Struct with a property that can be T.any(...), sorbet-schema will raise a CoercionNotSupportedError because it can't find a coercer for something of the type T::Private::Types::SimplePairUnion. This PR fixes that so that instead of trying to coerce T::Private::Types::SimplePairUnion it iterates through all the types in that union object and tries coercing into all those types.

@antoinesaliba antoinesaliba requested a review from maxveldink July 3, 2024 05:26
@antoinesaliba antoinesaliba force-pushed the antoine.dealing_with_multiple_types branch from 2102a83 to b792283 Compare July 3, 2024 05:34
@antoinesaliba antoinesaliba marked this pull request as ready for review July 3, 2024 05:36

class Person < T::Struct
include ActsAsComparable

const :name, String
const :age, Integer
const :ruby_rank, RubyRank
const :stone_rank, T.any(RubyRank, DiamondRank)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if you prefer what you had as ruby_rank and I can just create a different think rather than piggy-backing on what you had

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool with piggy backing on this struct 👍🏻

@maxveldink maxveldink merged commit c0c2ca3 into main Jul 5, 2024
5 checks passed
@maxveldink maxveldink deleted the antoine.dealing_with_multiple_types branch July 5, 2024 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants