Skip to content

[22.4.2-5] When adding keys from non-default namespaces, incorrect TS suggestions are given that omit the namespace from the key #1886

@rodrigojmr

Description

@rodrigojmr

🐛 Bug Report

For an non-default namespace (ex: an extra namespace with { "testing": "extra string" }), key suggestions are being shown without the namespace.

Suggestions show

  const { t } = useTranslation(["common", "extra"]);
  t('test') // "testing" shows up in TS autocomplete, but should not

Gives expected TS error after writing testing

Argument of type '"testing"' is not assignable to parameter of type 'TemplateStringsArray | "extra:testing" | "common:documentation" | "common:loading" | "common:this-stack-uses" | "common:techcard" | "common:techcard.nextjs" | "common:techcard.prisma" | "common:techcard.nextjs.description" | "common:techcard.prisma.description" | (TemplateStringsArray | ... 8 more ... | "common:tech...'.typescript(2769)

To Reproduce

Set up TS as per preferred approach, with objects declared as const.
Created an extra namespace with a single testing key.

i18next.d.ts

import "i18next";
import locales from "./public/locales";

declare module "i18next" {
  interface CustomTypeOptions {
    defaultNS: "common";
    resources: typeof locales["en"];
  }
}

public/locales/en/extra.json

{
  "testing": "extra string"
}

Codesandboxes:
22.4.5

22.4.2

22.4.1 (not reproducible)

Also reproducible in https://github.com/BearStudio/start-ui-web by upgrading i18next to 22.4.2-5

22.4.2+
Code_TNyPrhf1DO

22.4.1
Code_QYMLwOO9KR

Expected behavior

Suggestions should not omit namespaces for non-default key values.

  const { t } = useTranslation(["common", "extra"]);
  t('testi') // "testing" does not show up in TS autocomplete, only "extra:testing"

Your Environment

  • runtime version: i.e. node 18.12.1
  • i18next version: i.e. 22.4.2 to 22.4.5
  • os: WSL2 Linux

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