Skip to content

Error: Type instantiation is excessively deep and possibly infinite. #54943

@crazyair

Description

@crazyair

Bug Report

🔎 Search Terms

error TS2589: Type instantiation is excessively deep and possibly infinite.

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 4.9 and 5.1.6
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

export type DefineObjPath<T, T1 extends any[] = unknown[]> = {
    [P in keyof T]: Required<T>[P] extends object
        ? DefineObjPath<Required<T>[P], T1[number] extends string ? [...T1, P] : [P]>
        : P | [...T1, P];
}[keyof T];

export interface TableProps<T = any> {
    dataSource?: T[];
    columns?: { dataIndex?: DefineObjPath<T> }[];
}

export function func<T = any>(props: TableProps<T>) {
    return props;
}

export const demo = func({ dataSource: [{ a: { b: 'c' } }], columns: [{ dataIndex: ['a', 'b'] }] });

// check type
export type checkType = DefineObjPath<{ a: { b: string } }>;

🙁 Actual behavior

image

🙂 Expected behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    UnactionableThere isn't something we can do with this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions