Type issue when using localization #10119
Replies: 5 comments
-
@r1tsuu I wonder if this was a regression. Did you make any related changes recently? |
Beta Was this translation helpful? Give feedback.
-
@DanRibbens I don't think so. We never supported types for |
Beta Was this translation helpful? Give feedback.
-
@thibault-chausson the reason why you can't access We could make an optional type generation for |
Beta Was this translation helpful? Give feedback.
-
Thank you for your feedback! It would be very handy for generating sitemaps, for instance, because I have different article slugs in French and English, and I want to properly set up alternates tags for article localization. Also, if we could do this with Strapi using |
Beta Was this translation helpful? Give feedback.
-
Exactly, agree. {
slug: 'posts-test',
hooks: {
// in beforeRead all the locales are available.
beforeRead: [
({ doc }) => {
doc.localizedSlugs = doc.slug
},
],
},
fields: [
{
name: 'slug',
type: 'text',
localized: true,
},
{
name: 'localizedSlugs',
type: 'group',
virtual: true,
admin: {
hidden: true,
},
fields: [
{
name: 'en',
type: 'text',
},
{
name: 'es',
type: 'text',
},
],
},
],
}, Generated type: /**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "posts-test".
*/
export interface PostsTest {
id: string;
slug?: string | null;
localizedSlugs?: {
en?: string | null;
es?: string | null;
};
updatedAt: string;
createdAt: string;
} |
Beta Was this translation helpful? Give feedback.
-
Describe the Bug
I use the feature that allows multiple languages on a field, like this:
Then I configure Payload as follows:
When everything is set up correctly, I want to retrieve an article like this, but I get a type error (or the type isn’t defined) for
articles.docs[0].title.en
:I get this error:
But in the terminal, with a
console.log
, we can see the JSON structure perfectly.Link to the code that reproduces this issue
https://github.com/thibault-chausson/bug-payload
Reproduction Steps
To reproduce this bug, use PostgreSQL, initialize the .env file with your database URL.
Run the application with:
pnpm dev
Add one article in French and one in English.
Then go to localhost:3000 and look at the result in the terminal. You’ll see the JSON:
Which area(s) are affected? (Select all that apply)
area: docs
Environment Info
Beta Was this translation helpful? Give feedback.
All reactions