Skip to content

Mapped Type + Recursive Type = Type instantiation is excessively deep and possibly infinite (2589) #45411

Open
@yoni-rapoport

Description

@yoni-rapoport

Bug Report

This is the simplest repro of an issue that prevents the use of recursive mapped types for any type that contain any properties (or properties of properties etc...) typed using a recursive type alias.

🔎 Search Terms

  • Type Alias
  • Mapped Types
  • Recursive Types
  • Type instantiation is excessively deep and possibly infinite

🕗 Version & Regression Information

Since 3.7

⏯ Playground Link

Playground Link

💻 Code

type RecursiveType = string | number | RecursiveType[];

type MappedType<T> = {
  [K in keyof T]: MappedType<T[K]>;
};

type MappedTypeOfRecursiveType = MappedType<RecursiveType>;

🙁 Actual behavior

Type instantiation is excessively deep and possibly infinite. (2589)

🙂 Expected behavior

Expected to compile successfully

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions