Skip to content

TS throw Type instantiation is excessively deep and possibly infinite when there are loads of keys in Trans component #1394

Closed
@Ambrozy

Description

@Ambrozy

🐛 Bug Report

The same issue as: #1222
But appears in Trans component only.

To Reproduce

A codesandbox example.

Expected behavior

No typescript errors

Your Environment

  • typescript: 4.35
  • i18next: 21.3.3
  • react-i18next: 11.13.0

Solution

Remove K generic.

    type I18nKeyType<N extends Namespace> = TFuncKey<N> extends infer A ? A : never;

    interface TransProps<N extends Namespace = DefaultNamespace, E extends Element = HTMLDivElement>
        extends React.HTMLProps<E> {
        children?: React.ReactNode;
        components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
        count?: number;
        defaults?: string;
        i18n?: i18n;
        i18nKey?: I18nKeyType<N> | I18nKeyType<N>[];
        ns?: N;
        parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
        tOptions?: {};
        values?: {};
        t?: TFunction<N>;
    }

    function Trans<N extends Namespace = DefaultNamespace, E extends Element = HTMLDivElement>(
        props: TransProps<N, E>,
    ): React.ReactElement;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions