Skip to content

Inconsistent numbering for type assertions #148

@joshkel

Description

@joshkel

🐛 Bug Report

TypeScript type assertions (as in #133) result in placeholders being numbered differently. Since type assertions go away at runtime, this is incorrect. (It results in placeholders that react-i18next doesn't recognize at runtime.)

To Reproduce

export function Test() {
  const one = "one";
  const two = "two";
  return (
    <Trans>
      <div>
        <a>{{ one } as any}</a> to <b>{{ two } as any}</b>
      </div>
    </Trans>
  );
}

With type assertions, i18next-cli extract extracts "<0><1>{{one}}</1> to <4>{{two}}</4></0>".

Without the as any type assertions, it extracts "<0><1>{{one}}</1> to <3>{{two}}</3></0>".

From what I can tell, "<0><1>{{one}}</1> to <3>{{two}}</3></0>" matches what react-i18next expects at runtime.

Expected behavior

Results that are consistent and compatible with react-i18next

Your Environment

  • runtime version: Node.js 24
  • i18next version: i18next 25.7.2, react-i18next 16.5.0, i18next-cli 1.31.0
  • os: Mac

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions