Skip to content

[22.4.5] TS autosuggests both prefixed and un-prefixed key, with the prefixed giving a TS error. #1887

@momentiris

Description

@momentiris

🐛 Bug Report

t function autocompletes with duplicate entries, both with and without namespace prefix. If I use the prefixed version, I get a TS error.

const { t } = useTranslation();

const foo = t('ABORT') 
const foo = t('translation:ABORT')

First problem is that both of these shows up as suggestions. Second problem is that using the second version gives a TS error:

[tsserver 2769] [E] No overload matches this call.                                                                                                                                                    
 Overload 1 of 12, '(key: Normalize<{ ABORT: string;.... 

To Reproduce

Set up TS as per preferred approach, with objects declared as const.

i18n.ts

import { initReactI18next } from 'react-i18next';
import i18n from 'i18next';

import sv from './../assets/locales/sv/translation.json';

export const defaultNS = 'translation';
export const resources = { sv: { translation: sv } } as const;

export const i18nConfig = i18n.use(initReactI18next).init({
  lng: 'sv',
  defaultNS,
  resources,
});

Codesandbox:
22.4.5

Screenshot 2022-12-14 at 15 20 27

Screenshot 2022-12-14 at 15 23 33

Expected behavior

Suggestions should not show both unprefixed and prefixed.
No suggestion should give an error.

  const { t } = useTranslation();
  t('') // only "FOO" should show up as suggestion.

Your Environment

  • runtime version: browser lastest chrome, node 16.15.1
  • i18next version: 22.4.2 to 22.4.5
  • os: Mac OS Monterey 12.2.1

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions