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

Trans shouldUnescape prop is missing in .d.ts #1428

Closed
predragnikolic opened this issue Dec 13, 2021 · 6 comments · Fixed by #1429
Closed

Trans shouldUnescape prop is missing in .d.ts #1428

predragnikolic opened this issue Dec 13, 2021 · 6 comments · Fixed by #1429
Assignees

Comments

@predragnikolic
Copy link

🐛 Bug Report

Based on the documentation for the <Trans /> component
https://react.i18next.com/latest/trans-component#trans-props

There is a shouldUnescape prop,
but that prop doesn't exist in the index.d.ts file,
so typescript complains

To Reproduce

Try to use the shouldUnescape prop on the Trans compoent.

export function SafeHtml({ htmlString }: Props) {
  return <Trans
    shouldUnescape
//  ^^^^^^^^^^^^^^  TS ERROR: Property 'shouldUnescape' does not exist on type 'IntrinsicAttributes & TransProps<Normalize<
    defaults={htmlString}
    components={ALLOWED_TAGS} />
}

Expected behavior

No errors should be reported.

Your Environment

  • runtime version: node v14
  • i18next version: 19.8.7
  • os: Mac
  • any other relevant information
@adrai
Copy link
Member

adrai commented Dec 13, 2021

Would you like to send a Pull Request to address this? Remember to add unit tests.

@predragnikolic
Copy link
Author

I tried to override the react-i18next type:

declare module "react-i18next" {
  // add i18n translations type safty-https://stackoverflow.com/questions/58277973/how-to-type-check-i18n-dictionaries-with-typescript#answer-65348832
  export function Trans<
  K extends TFuncKey<N> extends infer A ? A : never,
  N extends Namespace = DefaultNamespace,
  E extends Element = HTMLDivElement
+  >(props: TransProps<K, N, E> & { 
+    shouldUnescape?: boolean
+   }): React.ReactElement;
}

And that silences the typescript error,
BUT although I added the shouldUnescape prop:

import { Trans } from "react-i18next"

export function Example() {
  return <Trans
    shouldUnescape
    defaults={"<p>Hello&nbsp;you</p>"} />
}

characters like &nbsp; are still not escaped.

Do you see any mistake in my code?

@predragnikolic
Copy link
Author

Would you like to send a Pull Request to address this?

No, not at the moment :)

@adrai
Copy link
Member

adrai commented Dec 13, 2021

@pedrodurek Can you help?
//cc: @cuyl

@predragnikolic
Copy link
Author

@adrai,
btw thanks for the quick replies!

@pedrodurek pedrodurek mentioned this issue Dec 13, 2021
5 tasks
@adrai
Copy link
Member

adrai commented Dec 13, 2021

Thanks to @pedrodurek this should be fixed with v11.15.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants