grantila / suretype

Typesafe JSON (Schema) validator
502 stars 9 forks source link

Record schema? #4

Closed calvinl closed 3 years ago

calvinl commented 3 years ago

Hi there,

This project looks really promising! I was wondering if there was a way to provide a loose record schema that may have arbitrary keys/values. Basically the typescript equivalent of Record<string, unknown>?

Thanks for the great work on this!

grantila commented 3 years ago

You can do v.object({}).additional(true). This is a shortcut for v.object({}).additional(v.any()) which creates a type identical to Record<string, any>. There is no unknown support yet, perhaps that's a good addition to add - it's certainly more safe than any.

grantila commented 3 years ago

Thanks for the feedback, and sorry for not having any API documentation yet. It's coming!

calvinl commented 3 years ago

Thank you!

Just noting here that the killer feature is converting to JSON schema for me. I came from previously using zod which has great typescript support (including the nested compilation mentioned in #5). I had written a custom zodToJsonSchema converter but it's not quite as robust as suretype.

Thanks again! Closing this ticket.