RJ
RJ2y ago

TS readonly Convex values

I've run into the issue a few times of having a readonly value, like readonly number[], which I'd like to pass in as an argument to something like db.insert for a table whose schema is v.array(v.number()). TypeScript sees readonly number[] as unassignable to the type number[], and gives me a type error. I wonder how the DX might be improved here? Would it be too ungainly to have v.array<T> produce the type readonly T[] | T[] (same with v.object)? For what it's worth, I just about never use readonly in my own code (and am not too familiar even with what it purports to guarantee, or not)—these examples have come from types in third-party libraries.
2 Replies
Michal Srb
Michal Srb2y ago
Hey @RJ , this is great feedback, we can probably address this on our side by taking in readonly in the db. methods. We'll look into it. For now you'll need to cast the value.
RJ
RJOP2y ago
Yeah, that’s what I’ve been doing. Thanks @Michal Srb!

Did you find this page helpful?