Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yoni-rapoport opened this issue Aug 11, 2021 · 2 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@yoni-rapoport
Copy link

yoni-rapoport commented Aug 11, 2021

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

@orouz
Copy link
Contributor

orouz commented Aug 11, 2021

somehow it works with a key remapping of K to K

Playground

also worth looking into #45025

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 13, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 13, 2021
@Gregoor
Copy link

Gregoor commented Apr 2, 2023

I am running into this right now as well, and can confirm that it's still a problem with both v4 and v5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants