GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(compilerOption): add instantiationDepthLimit and instantiationCountLimit by jjangga0214 · Pull Request #44997 · microsoft/TypeScript

Conversation

@jjangga0214

@jjangga0214 jjangga0214 commented Jul 13, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #34933.

I am not familiar with this project structure. This PR might be incomplete, so I hope someone contributes to complete it.
I only edited 3 files, and didn't touch Diagnostics though I referred to new fields from it.

Please let users be able to adjust instantiationDepthLimit and instantiationCountLimit by their free decisions and responsibilities, instead of hard-coded values (50 and 5000000 for each).

Currently, the limitation thresholds are fixed to 50 and 5000000.

src/compiler/checker.ts

if (
  instantiationDepth === 50 ||
  instantiationCount >= 5000000
) {
  // We have reached 50 recursive type instantiations and there is a very high likelyhood we're dealing
  // with a combination of infinite generic types that perpetually generate new type identities. We stop
  // the recursion here by yielding the error type.
  error(
    currentNode,
    Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite
  );
  return errorType;
}

I think compilerOptions would be great solution for these to be configurable.

{
  "compilerOptions": {
    "instantiationDepthLimit": 100,
    "instantiationCountLimit": 10000000
  }
}

Thanks :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yuhr, TimPetricola, vuki656, twistedpair, karol-majewski, kirstenlindsmith, SancheZz, Mel0nHead, JoseLion, the0rem, and 97 more reacted with thumbs up emoji JoshuaWise, TristanBarlow, Methrat0n, Enteleform, kusyka911, fishactual, zinovev-space, matt-morris, Shayan-To, yuhr, and 5 more reacted with heart emoji
All reactions
  • 👍 107 reactions
  • ❤️ 15 reactions
@jjangga0214
feat(compilerOption): add instantiationDepthLimit and instantiationCo…
81ebc4a
…untLimit

Close microsoft#34933
@typescript-bot TypeScript Bot (typescript-bot) assigned Wesley Wigham (weswigham) Jul 13, 2021
@typescript-bot TypeScript Bot (typescript-bot) added the For Milestone Bug PRs that fix a bug with a specific milestone label Jul 13, 2021
@ghost

Deleted user (ghost) commented Jul 13, 2021 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jjangga0214 jjangga0214 mentioned this pull request Jul 13, 2021
“Type instantiation is excessively deep and possibly infinite” but only in a large codebase #34933
Open
@jjangga0214
chore(compilerOption): recomment
02dbb75
@jjangga0214 jjangga0214 mentioned this pull request Jul 15, 2021
Increase type instantiation depth limit #45025
Merged
@kiprasmel

Kipras Melnikovas (kiprasmel) commented Jul 30, 2021

Copy link
Copy Markdown

See also #29602

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adam-thomas-privitar Adam Thomas (adam-thomas-privitar) mentioned this pull request Aug 11, 2021
Chakra does not compile with latest Typescript 4.3.x: Type instantiation is excessively deep chakra-ui/chakra-ui#4226
Closed
sandersn
Nathan Shively-Sanders (sandersn) requested changes Aug 14, 2021
View reviewed changes

@sandersn Nathan Shively-Sanders (sandersn) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anders Hejlsberg (@ahejlsberg) plans to increase the limit in #45025, but so far we don't want to make any limits configurable, since they're such fluctuating implementation details.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jjangga0214

jjangga0214 commented Aug 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Nathan Shively-Sanders (@sandersn)

Though it can be viewed as an implementation detail, there're high demands for configuration (See thumbs and overall attention of people).

What's more, There're still cases the increased limit can't cover.

Thus, how about experimental configuration?

P.S. Actually I've already left a comment a month ago about experimental configuration on #45025, but nobody replied to this idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Aug 17, 2021

Copy link
Copy Markdown
Member

I can't stress enough that we don't think this is appropriate to expose as configuration. Today instantiation is a process with a particular memory and runtime cost that occurs during certain operations, but every aspect of that is an implementation detail that could change tomorrow, at which point the numeric limits specified at any given point in time do not translate to the same behavior any more.

This isn't a fix for the linked issue and, again, we do not consider this to be a "tunable" parameter.

cmlenz, micalevisk, and andrej-dyck reacted with thumbs up emoji Shayan-To, danielo515, PaperPlane01, danielmbirochi, uetchy, Renegatto, brandonwkipp, giyeonkwon, vicary, robberfree, and 4 more reacted with thumbs down emoji SoenkeHu, Egor-Koldasov, Shayan-To, and klauszhang reacted with confused emoji
All reactions
  • 👍 3 reactions
  • 👎 14 reactions
  • 😕 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as draft August 17, 2021 20:08
@Jamesgt

Tamas Gemes (Jamesgt) commented Jan 20, 2022

Copy link
Copy Markdown

Ok, so you don't consider it, but then I guess more and more "solution" will appear.

Since I am not allowed to use a patched tsc, to compile my code I had to use // @ts-ignore (see https://stackoverflow.com/a/64688342/146334) to have my complex mongodb schema built.

I don't see why it is better to mute errors (with known side effects) instead of allowing parameters tuning for users. The default value can stay in your ownership, so 99.999% of users will use that. If even in a patch version, the behavior changes, we still can adapt to it using the same, or new experimental configuration.

Shayan-To, DanielSWolf, Ricardo-Marques, mosade, alexandrchebotar, danielmbirochi, uetchy, avasilic, and Emanuel-Manrique reacted with thumbs up emoji
All reactions
  • 👍 9 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@danielo515

Daniel Rodríguez Rivero (danielo515) commented Mar 24, 2022

Copy link
Copy Markdown

I have the same problem while running typeof someJsonObject where the json object has something around 3k properties.
Does anyone know at least where is the limit? Or should I go and test recursively until I find it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Ricardo-Marques

Ricardo "Meida" Marques (Ricardo-Marques) commented Mar 29, 2022

Copy link
Copy Markdown

The depth fix mentioned in this article resolved my problem, even when sticking to an initial depth of 1
https://www.angularfix.com/2022/01/why-am-i-getting-instantiation-is.html

I would love to know why 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nopeless

nopeless (nopeless) commented Nov 11, 2022

Copy link
Copy Markdown

I can't stress enough that we don't think this is appropriate to expose as configuration. Today instantiation is a process with a particular memory and runtime cost that occurs during certain operations, but every aspect of that is an implementation detail that could change tomorrow, at which point the numeric limits specified at any given point in time do not translate to the same behavior any more.

This isn't a fix for the linked issue and, again, we do not consider this to be a "tunable" parameter.

Sorry for commenting on an old post, but changing the parameters to something larger temporarily would allow the developer to determine whether their type is actually recursive or infinite

giyeonkwon, thelinuxlich, Jackman3005, rostislav-simonik, mohe2015, and klauszhang reacted with thumbs up emoji
All reactions
  • 👍 6 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MartinJohns Martin Johns (MartinJohns) mentioned this pull request Jan 17, 2024
Bug that kill TypeScript build time #57075
Closed
@sandersn

Nathan Shively-Sanders (sandersn) commented Apr 14, 2025

Copy link
Copy Markdown
Member

I'm closing this PR because it is stale and the approach is not one we want to take.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sandersn Nathan Shively-Sanders (sandersn) closed this Apr 14, 2025
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sandersn Nathan Shively-Sanders (sandersn) sandersn requested changes
Copilot code review Copilot
Copilot will automatically review once the pull request is marked ready for review

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@weswigham Wesley Wigham (weswigham)

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

“Type instantiation is excessively deep and possibly infinite” but only in a large codebase

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@jjangga0214 @kiprasmel @RyanCavanaugh @Jamesgt @danielo515 @Ricardo-Marques @nopeless @sandersn @weswigham @typescript-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.