Open jshirley opened 1 month ago
Thanks for the report. It might be better to relax this constraint for better DX. I think config.time_zone
is set by default. If 99% of the applications will have it set I think it's better to change the type to ActiveSupport::TimeWithZone
.
@ipvalverde thoughts?
Thanks for raising this! Happy to have it changed to a ActiveReport::TimeWithZone
to quickly fix this.
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 TimeWithZone
behaves like a Time
object.
Would it make sense to add something like that the rbi central repo as well? It is a sensible change given TimeWithZone behaves like a Time object.
@ipvalverde Yeah I'm okay with that too.
Up for review: https://github.com/Shopify/rbi-central/pull/262
Problem
We started to get errors when typechecking, tracing back to https://github.com/Shopify/rbi-central/pull/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!
Sorbet typechecker 0.5.11218 git a4457bfc25b26f8953eef8e529ec5a7488f2e1ac debug_symbols=true clean=1