Reputation: 25
I've installed Sorbet in a Rails codebase and am seeing many instances of the following error:
sorbet/rbi/sorbet-typed/lib/activerecord/all/activerecord.rbi:958:
Method ActiveRecord::ConnectionAdapters::TableDefinition#column redefined without matching argument count. Expected: 3, got: 5 https://srb.help/4010
958 | def column(
959 | name,
960 | type,
961 | index: nil,
962 | default: nil,
963 | **options
964 | ); end
sorbet/rbi/gems/activerecord.rbi:5256: Previous definition
5256 | def column(name, type, **options); end
To make the type errors go away, I either have to change typed: true
to typed: false
in one of the files (which excludes some of the types that don't overlap), or I have to manually go in and delete/comment out the overlapping methods (which is time-consuming and brittle).
I'm wondering if there's some sort of programmatic solution, where I can say "in case of conflict, use the method with higher arity" or "always choose the sorbet-typed definition."
Again this is in a Rails codebase but I imagine this would exist for any conflict between the hand-generated and auto-generated RBIs.
Upvotes: 0
Views: 617
Reputation: 870
I wrote some of these methods, unfortunately since "Shapes" (Sorbet's experimental implementation of typeable Hashes) don't allow optional keys, they can't be used to represent these methods accurately. As a result, the arity of a lot of methods - especially complex stuff in Rails - is different between sorbet-typed and sorbet's autogenerated files.
I've just been using srb rbi suggest-typed
to automatically set the typedness of files in my repo, and it just marks those as false. As far as I can tell, the type information from sorbet-typed is still used even if the file is marked as false (though I should probably look into that more to verify that that's the case).
Unfortunately I don't have a better solution for the problem at the moment, but just using suggest-typed seems to be sufficient for me so far.
Upvotes: 1