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

Wrong type generation using sanity typegen #8202

Open
Kuboczoch opened this issue Jan 7, 2025 · 0 comments
Open

Wrong type generation using sanity typegen #8202

Kuboczoch opened this issue Jan 7, 2025 · 0 comments

Comments

@Kuboczoch
Copy link

Describe the bug

The typegen is returning the wrong type

To Reproduce

Steps to reproduce the behavior:

  1. This is my query:
Groq query
const howToTestPageQuery = groq`*[_type == "testingPage" && (language == $regionLanguage || language == $language || language == '${DEFAULT_LANGUAGE}') && !(_id match 'drafts*')]{
  ${SORT_ORDER},
  hero{
    ${HERO} 
  },
  modules[]{
    _key,
    _type,
    _type == "informationSection" => {
      title,
      cards     
    },
    _type == "featureSection" => {
      title,
      subtitle,
      features     
    },
    _type == "video" => {
      url,
      type,
      preview,
      meta,
      filename,
      id
    },
    _type == "resultSection" => {
      title,
      subtitle, 
      imageMobile, 
      imageDesktop,
      button
    },
  },
  ${SEO},
} | order(sortOrder desc)[0]
`;
  1. It produces this type:
Generated type using `sanity typegen generate`
export type TestingPage = {
_id: string;
_type: 'testingPage';
_createdAt: string;
_updatedAt: string;
_rev: string;
store?: ManualSlug;
seo?: SeoPage;
hero?: Banner;
modules?: Array<
  | {
      title?: string;
      cards?: Array<{
        title?: string;
        text?: string;
        _key: string;
      }>;
      _type: 'informationSection';
      _key: string;
    }
  | {
      title?: string;
      subtitle?: string;
      features?: Array<
        {
          _key: string;
        } & Feature
      >;
      _type: 'featureSection';
      _key: string;
    }
  | {
      title?: string;
      subtitle?: string;
      button?: Link;
      imageDesktop?: ShopifyAsset;
      imageMobile?: ShopifyAsset;
      _type: 'resultSection';
      _key: string;
    }
  | ({
      _key: string;
    } & ShopifyAsset)
>;
language?: string;
};

// Not part of this particular query but required to get the context
export type ShopifyAsset = {
_type: 'shopify.asset';
filename?: string;
id?: string;
meta?: ShopifyAssetMetadata;
preview?: ShopifyAssetPreview;
type?: string;
url?: string;
};
3. My module of `_type` `video` is generated using the wrong type of the `ShopifyAsset` `shopify.asset`.

Expected behavior

The module should been of a _type video.
So instead of:

      | ({
        _key: string;
      } & ShopifyAsset)

I want to get the following:

      | ({
        _key: string;
        _type: 'video'
      } & Omit<ShopifyAsset, '_type'>)

Which versions of Sanity are you using?

@sanity/cli (global)  3.66.1 (latest: 3.68.3)
sanity                3.51.0 (latest: 3.68.3)

What operating system are you using?
Windows, Linux, and macOS

Which versions of Node.js / npm are you running?

10.5.0
v20.12.2

Additional context

If this is on my side, then I apologize in advance.

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