Skip to content

Argument of type '"markDefs[]"' is not assignable to parameter of type 'never'. #369

Open
@tobeycodes

Description

@tobeycodes

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

Code Sandbox link

No response

Bug report

I am working on building out a scaffold for sanity projects and I have been experimenting with groqd for better type saftey over groq. Here is where the issue exists https://github.com/vueza/create-sanity-app/blob/feature/groqd/apps/cms/src/fragments/block.ts#L11

I am extracting the content block type used with portable text and created a fragment for this. When trying to get the field markDefs[] I get the error Argument of type '"markDefs[]"' is not assignable to parameter of type 'never'.. Typically the autocomplete would show all the possible fields but for me fieldName is never.

If I copy the actual type extracted (as I have shown below the commented out Extract) the same error exists but the error goes away if I remove _type: "block". The field(fieldName) then autocompletes all the fields and the type error for markDefs[] goes away.

import type { InferFragmentType } from "groqd";
import { z } from "zod";
import type { internalGroqTypeReferenceTo } from "../../sanity.types";
import { q } from "../client/client";
import { link } from "./link";

//type Block = Extract<Content[number], { _type: "block" }>;

type Block = {
  children?: Array<{
    marks?: Array<string>;
    text?: string;
    _type: "span";
    _key: string;
  }>;
  style?: "normal" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "blockquote";
  listItem?: "bullet" | "number";
  markDefs?: Array<{
    type: "href" | "page" | "post";
    href?: string;
    page?: {
      _ref: string;
      _type: "reference";
      _weak?: boolean;
      [internalGroqTypeReferenceTo]?: "page";
    };
    post?: {
      _ref: string;
      _type: "reference";
      _weak?: boolean;
      [internalGroqTypeReferenceTo]?: "post";
    };
    _type: "link";
    _key: string;
  }>;
  level?: number;
  _type: "block";
  _key: string;
};

export const block = q.fragment<Block>().project((sub) => ({
  "...": true,
  markDefs: sub.field("markDefs[]").project((sub) => ({
    _key: z.string(),
    ...sub.conditionalByType({
      link: {
        _key: z.string(),
        ...link,
      },
    }),
  })),
}));

export type BlockFragment = InferFragmentType<typeof block>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggroqd-v1Related to the newer `v1.x` package

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions