Skip to content

RangeError: Maximum call stack size exceeded at getAwaitedTypeNoAlias #49723

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

Closed
jakebailey opened this issue Jun 29, 2022 · 5 comments
Closed
Assignees

Comments

@jakebailey
Copy link
Member

jakebailey commented Jun 29, 2022

Bug Report

Moved from #47208 (comment)

πŸ”Ž Search Terms

RangeError Maximum call stack size exceeded getAwaitedTypeNoAlias

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried.

⏯ Playground Link

Playground Link

πŸ’» Code

type T = 1 | Promise<T> | T[];

export async function myFunction(param: T) {
  const awaited = await param
}

πŸ™ Actual behavior

     RangeError: Maximum call stack size exceeded
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36632:70)
      at mapper (src\compiler\checker.ts:36628:71)
      at mapType (src\compiler\checker.ts:23959:95)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36629:60)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36678:37)
      at mapper (src\compiler\checker.ts:36628:71)
      at mapType (src\compiler\checker.ts:23959:95)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36629:60)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36678:37)
      at mapper (src\compiler\checker.ts:36628:71)
      at mapType (src\compiler\checker.ts:23959:95)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36629:60)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36678:37)
      at mapper (src\compiler\checker.ts:36628:71)
      at mapType (src\compiler\checker.ts:23959:95)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36629:60)
      at getAwaitedTypeNoAlias (src\compiler\checker.ts:36678:37)

πŸ™‚ Expected behavior

No crash.

@jakebailey
Copy link
Member Author

Actually, this is a dupe of #49646 and should be fixed by #49677.

@fatcerberus
Copy link

type T = 1 | Promise<T> | T[];

I'm not sure how to read this type. Does this mean T is either:

  • A 1
  • An array of 1s
  • An array of arrays of 1s
  • A promise for a 1
  • An array of promises for 1s
  • A promise for an array of 1s
  • A promise for an array of promises for 1s
  • etc., inductively

...or is it just a completely circular definition?

@jakebailey
Copy link
Member Author

It's just circular; there's an error message for types like these that can't be resolved (see the linked PR).

@fatcerberus
Copy link

That's what I thought; I guess I'm just confused because I thought when TS produced an error for a circular type it subsequently treated the type as any, which should be enough to prevent the crash on await... I guess the bug is that this case isn't being detected as circular

@Andarist
Copy link
Contributor

I guess the bug is that this case isn't being detected as circular

Yep, notice how I've fixed this by just adding the circularity tracking~ here:
https://github.com/microsoft/TypeScript/pull/49677/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R36628

Andarist added a commit to Andarist/TypeScript that referenced this issue Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants