payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
27.76k stars 1.72k forks source link

fix: labelfunction type error when merging custom keys #9335

Open marwinhormiz opened 3 days ago

marwinhormiz commented 3 days ago

When creating custom translations and merging the custom translation keys with the default translation keys, and then pass it to the generic TFunction type, Typescript complains that the function does not satisfy the LabelFunction type in a label field.

The reason for this is that the LabelFunction type is not generic, and it's always using the default TFunction which itself uses the DefaultTranslationKey if no type is passed to it.

This is solved by making the LabelFunction generic and forward the TTranslationKeys to the TFunction type.

Following this documentation: https://payloadcms.com/docs/configuration/i18n#typescript

Example: image