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

fix: add generic to LabelFunction to prevent type error for custom translation keys #9335

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

marwinhormiz
Copy link
Contributor

@marwinhormiz marwinhormiz commented Nov 19, 2024

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

@marwinhormiz marwinhormiz changed the title fix: LabelFunction type error when merging custom keys fix: labelfunction type error when merging custom keys Nov 22, 2024
@AlessioGr AlessioGr changed the title fix: labelfunction type error when merging custom keys fix: add generic to LabelFunction to prevent type error for custom translation keys Nov 28, 2024
@AlessioGr AlessioGr enabled auto-merge (squash) November 28, 2024 21:21
@AlessioGr
Copy link
Member

Thank you!

@AlessioGr AlessioGr merged commit 27eeac2 into payloadcms:main Nov 28, 2024
55 checks passed
Copy link
Contributor

🚀 This is included in version v3.2.2

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

Successfully merging this pull request may close these issues.

2 participants