Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This gem works with Sorbet's static type checker and type definitions. It'll return a statically-typed object or throws `T::CoercionError` if the coercion fails. It provides a simple and generic way of coercing types in a sorbet-typed project. It is particularly useful when we're dealing with external API responses and controller parameters. ```ruby converted = T::Coerce[<Type>].new.from(<value>) T.reveal_type(converted) # <Type> ``` The supported types include - Simple Types (Integer, String, etc.) - Custom Types: If the values can be coerced by `.new` - `T.nilable(<supported type>)` - `T::Array[<supported type>]` - Subclasses of `T::Struct` We don't support - `T::Hash` (currently) - `T.any(<supported type>, ...)`: A union type other than `T.nilable`
- Loading branch information