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

Support TypeScript type casts in JSX #603

Closed
joshkel opened this issue Jun 14, 2022 · 1 comment
Closed

Support TypeScript type casts in JSX #603

joshkel opened this issue Jun 14, 2022 · 1 comment

Comments

@joshkel
Copy link
Contributor

joshkel commented Jun 14, 2022

🚀 Feature Proposal

i18next-parser cannot currently handle TypeScript as casts within a JSX file. For example:

<Trans>
  Hello, <strong>{{name} as any}</strong>!
</Trans>

gets extracted as "Hello, <1>{{ name } as any}</1>!" instead of "Hello, <1>{{name}}</1>!".

Motivation

As discussed in i18next/react-i18next#1483, React 18's type definitions cause TypeScript to start throwing errors for code such as

<Trans>
  Hello, <strong>{{name}}</strong>!
</Trans>

since a { name } object is not a valid React child. react-i18next offers a new allowObjectInHTMLChildren option to adjust TypeScript's type definitions to allow this; however, it's a fairly drastic option and causes all React children everywhere to allow arbitrary objects (even if they're not part of <Trans>).

An alternative is to use an as any cast (or similar) at the call site:

<Trans>
  Hello, <strong>{{name} as any}</strong>!
</Trans>

However, i18next-parser doesn't currently parse this properly.

Example

See above.

@karellm
Copy link
Member

karellm commented Oct 5, 2022

Deployed as part of 6.6.0

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

2 participants