Skip to content
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

How to type default within a select #271

Open
2 tasks done
b3nk3 opened this issue Mar 3, 2024 · 0 comments
Open
2 tasks done

How to type default within a select #271

b3nk3 opened this issue Mar 3, 2024 · 0 comments

Comments

@b3nk3
Copy link
Contributor

b3nk3 commented Mar 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Question

Hey there, I am using a `select` for my portable text content block and am running into issues, when trying to type `default`.


const unsupportedTypeBlockSelection = {
  _key: q.string(),
  _type: ['"unsupported"', q.literal('unsupported')],
  unsupportedType: ['_type', q.string()],
};

export type UnsupportedBlockType = TypeFromSelection<
  typeof unsupportedTypeBlockSelection
>;

I've been getting an error for typing the unsupported type:

Type '(string | ZodLiteral<"unsupported">)[]' is not assignable to type '[string, ZodType<any, ZodTypeDef, any>]'.
        Target requires 2 element(s) but source may have fewer.ts(2344)

My goal is to have a strict type in my SanityContent component

type ContentProps = {
  value: (PortableTextBlock | CodeBlockType | ImageBlockType | UnsupportedBlockType )[];
};

I can of course get around this by using TypedObject from @portabletext/types but that defies the point of strongly typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant