-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues building dynamic fields; SchemaTypeDefinition
equivalent?
#703
Comments
It's seeming like @sanity-typed really doesn't work in situations where types cannot be inferred: defineField({
name: "example",
type: "array",
of: [{ type: "string" }].map((f) => defineArrayMember(f)),
}) This yields errors on
Normally I'd explicitly type the array to resolve this, but without the means to do so it seems like my hands are tied. |
SO. I'm going to remove this restriction in the next version. I think that use cases like this are unavoidable and having sanity-typed be this strict on the |
When #801 gets deployed, that may help with your issue! |
I'm exploring using
sanity-typed
, but with a relatively simple studio I'm running into some issues. One I am not sure how to proceed on is figuring out how to handle dynamically defined schemas. For example, I have a list of object types that are used like content modules (called "blocks" in this case). The definitions for each are exported in an array from a "blocks/index.ts" file. With the vanilla TS studio, I can do the following to define acontentBlocks
type that I can use as a field elsewhere:If I convert this over to
@sanity-typed/types
, I wind up with a slew of TS errors, most obviously fromSchemaTypeDefinition
not matching what@sanity-typed/types
is doing. I tried looking for an equivalent, but it seems like all of the utility types require a long list of generics to be passed in. I saw elsewhere that usingas const
on array members insideof
might be necessary, but that doesn't really work in a scenario where the value is not actually constant like this.Any direction or guidance on how to approach this?
The text was updated successfully, but these errors were encountered: