Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Get type of item in optional array #196

Answered by ricokahler
winsvold asked this question in Q&A
Discussion options

You must be logged in to vote

hi there!, thanks for the kind words.

I have two potential solutions for you:

  1. you could go into your schema field and add codegen: { required: true }. This will make the codegen assert your field as required (this will not be enforced so be careful to add the corresponding validation too.
export default {
  name: 'myDocument',
  type: 'document',
  fields: [
    {
      name: 'aRequiredField',
      type: 'string',
      // 👇👇👇
      codegen: { required: true },
      validation: (Rule) => Rule.required(),
      // 👆👆👆
    },
  ],
};
  1. you could create a typescript helper that allows you to reach into the object. I have made helpers like this before.
type MyDocument = { events?: Array<{_…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@winsvold
Comment options

Answer selected by winsvold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants