RJ
RJ14mo ago

StorageId branded type and validator

It would be cool if StorageId were a branded type (like Id) rather than just a type alias, and it would also be cool if there were a validator for storage IDs (e.g. v.storageId()).
3 Replies
ballingt
ballingt14mo ago
You're prescient, work with this as a side effect is underway
ian
ian12mo ago
This was done in a previous release, for anyone following up. I also realized this just works:
defineSchema({
table: defineTable({
field: v.string() as Validator<MyStringType>
})
)}
defineSchema({
table: defineTable({
field: v.string() as Validator<MyStringType>
})
)}
field will be typed as MyStringType and give you errors on functions like withIndex, and give you that type on returned documents.
Michal Srb
Michal Srb12mo ago
To clarify, we now have Id<"_storage"> which can be used in place of storage IDs. Similarly v.id("_storage") works.