question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

4.7 regression: Array.flat(infinity) leads to "Type instantiation is excessively deep and possibly infinite." error

See original GitHub issue

Bug Report

🔎 Search Terms

  • Array.flat
  • Type instantiation is excessively deep and possibly infinite.
  • Nested arrays

🕗 Version & Regression Information

  • This changed between versions 4.6 and 4.7

⏯ Playground Link

TypeScript Workbench with relevant code

💻 Code

interface Config {
  prop?: string;
}

interface ExtendedConfig extends Config {}

type NestedConfigs = Array<ExtendedConfig | NestedConfigs>;

const configs: NestedConfigs[] = [];

const flattened = configs.flat(Infinity);

🙁 Actual behavior

TypeScript raises the following error for the configs.flat(Infinity) call:

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

🙂 Expected behavior

No error should be raised.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
taylorfsteelecommented, May 31, 2022

Just ran into this as well, here’s a very concise example:

type StringOrStringArray = string | StringOrStringArray[];

const flatten = (...args: StringOrStringArray[]) => args.flat(Infinity);

Same exact error on args.flat(Infinity), “Type instantiation is excessively deep and possibly infinite.”

A quick solution for now is to assert your .flat argument as an integer:

args.flat(Infinity as 10)

Should make the error go away.

0reactions
tjjfvicommented, Jun 2, 2022

This could be addressed if a literal type for Infinity was added: playground link using 1e309

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type instantiation is excessively deep and possibly infinite #22
Getting a ts error: Type instantiation is excessively deep and possibly infinite. ts(2589) Minimal example: import {flatten} from ...
Read more >
Why am I getting "Type instantiation is excessively deep and ...
You'll notice in the Playground link that action has the error: "Type instantiation is excessively deep and possibly infinite".
Read more >
Announcing TypeScript 4.7 : r/typescript - Reddit
It looks like the toughest upgrade though, I'm getting a lot of Type instantiation is excessively deep and possibly infinite errors.
Read more >
gcc(1) - Linux manual page - man7.org
The gcc program accepts options and file names as operands. Many options have multi-letter names; therefore multiple single-letter options may not be grouped:...
Read more >
d2l-en.pdf - Dive into Deep Learning
16.6.2 Text Pair Classification or Regression ... due to the rapid development of deep learning, some code in the print edition may not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found