Skip to content

4.6.2 regression: Type instantiation is excessively deep and possibly infinite. #48552

@seansfkelley

Description

@seansfkelley

Bug Report

πŸ”Ž Search Terms

recursive conditional types

πŸ•— Version & Regression Information

  • This changed between versions 4.5.5 and 4.6.2

⏯ Playground Link

Playground Link

πŸ’» Code

type Query<T> = {
  [P in DeepKeys<T>]?: string;
};

type Primitive =
	| null
	| undefined
	| string
	| number
	| boolean
	| symbol
	| bigint;

type DeepKeys<T> = T extends Primitive
  ? never
  :
      | (keyof T & string)
      | {
          [P in keyof T & string]: T[P] extends (infer Inner)[]
            ? `${P}.${DeepKeys<Inner>}`
            : T[P] extends object
            ? `${P}.${DeepKeys<T[P]>}`
            : P;
        }[keyof T & string];

πŸ™ Actual behavior

Type instantiation is excessively deep and possibly infinite. at the ${P}.${DeepKeys<T[P]>} snippet.

πŸ™‚ Expected behavior

No error. Type properly resolves to dot-notation keys of input object.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

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