How to define circular type references in Sorbet?
How do I make this work?
class Subscription < T::Struct
const :transactions, T::Array[::Transaction]
end
class Transaction < T::Struct
const :subscription, T.nilable(Subscription)
end
Right now Ruby errors at line 2 with "uninitialized constant Transaction (NameError)".
Posted Nov 2, 2022, 3:47 PM UTC
25
if that is in the same file it should be T::Array[Transaction]
It is in the same file. But Transaction is defined after Subscription and so T::Array[Transaction] does not work.
are the two classes defined another class? Added those two T struct to a random class of mine and it worked for me.
I don't know what you mean, can you post an example?