-
Notifications
You must be signed in to change notification settings - Fork 42
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
Updated Time annotations breaks model.updated_at = Time.current
#261
Comments
Thanks for the report. It might be better to relax this constraint for better DX. I think @ipvalverde thoughts? |
Thanks for raising this! Happy to have it changed to a It works in core because we added the following shim: class ActiveSupport::TimeWithZone < Time; end Would it make sense to add something like that the rbi central repo as well? It is a sensible change given |
@ipvalverde Yeah I'm okay with that too. |
Up for review: #262 |
Is this now fixed by Shopify/tapioca#1962? Seems like it in my previously affected app. |
Problem
We started to get errors when typechecking, tracing back to #259 and want to ensure that either we're not using the annotations wrong, or the side effects here are intended.
Context
We have methods on some models that aren't complex, and set some fields and related timestamps. ActiveRecord expects the fields (e.g.,
updated_at
to beT.nilable(ActiveSupport::TimeWithZone)
):This is the generated rbi for that model:
The old method looked something like this (other fields removed):
Prior to this update, this worked and passed typechecking, now:
If I update the method with the
T.any(...)
and cast to what ActiveRecord is expecting, it will pass typecheck:This requires a bit of boilerplate, but it feels awkward that
self.updated_at = Time.current
now throws a typecheck error.It can be reproduced in a Rails app with generating a new model (e.g.,
bin/rails g model Example
) with the following contents:After generating rbi and running
srb tc
it fails typechecking.Thank you, and happy to help further debug this!
zone
andcurrent
methods inTime
#259Sorbet typechecker 0.5.11218 git a4457bfc25b26f8953eef8e529ec5a7488f2e1ac debug_symbols=true clean=1
The text was updated successfully, but these errors were encountered: