-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
If you find a security vulnerability, do NOT open an issue. Email security@sanity.io instead.
Describe the bug
i have the following query:
export const postQuery = groq`*[_type == "post" && slug.current == $slug] [0] {
"body": body[$locale],
${postFields}
}`;
*** This is working if i do directly access a locale: body.en
body is LocaleString which normally return
{
"en": "...",
"fr": "..."
}
But i pass a locale to only get the currently selected lang in my website, so body is a string. But for some reason, typegen is still generatin this type:
export type PostQueryResult = {
body: LocaleString | null;
...
}
To Reproduce
Steps to reproduce the behavior:
- Create LocaleString type
export default defineType({
title: "Localized string",
name: "localeString",
type: "object",
fieldsets: [
{
title: "Translations",
name: "translations",
options: { collapsible: true },
},
],
fields: supportedLanguages.map((lang) => ({
title: lang.title,
name: lang.id,
type: "string",
fieldset: lang.isDefault ? undefined : "translations",
})),
});
- Defined a field
defineField({
name: "title",
title: "Title",
type: "localeString",
validation: (rule) => rule.required(),
}),
- Make a query for a single locale at a type using a dynamic param
Expected behavior
I expect the typegen to generate the following type:
export type PostQueryResult = {
body: string | null;
...
}
Which versions of Sanity are you using?
@sanity/cli (global) 3.37.2 (up to date)
@sanity/eslint-config-studio 4.0.0 (up to date)
@sanity/vision 3.37.2 (up to date)
sanity 3.37.2 (up to date)
What operating system are you using?
Mac OS
Which versions of Node.js / npm are you running?
10.2.3
v18.19.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels