Skip to content

Infinite recursion with generics and recursive Promise type #49646

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
nicolo-ribaudo opened this issue Jun 22, 2022 · 0 comments · Fixed by #49677
Closed

Infinite recursion with generics and recursive Promise type #49646

nicolo-ribaudo opened this issue Jun 22, 2022 · 0 comments · Fixed by #49677
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@nicolo-ribaudo
Copy link

Bug Report

🔎 Search Terms

Maximum call stack size exceeded
InternalError: too much recursion
generics type parameter promise recursive crash getAwaitedTypeNoAlias

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 3.8.3 and 3.9.7
  • It still crashes in 4.8.0-dev.20220622

⏯ Playground Link

Playground link with relevant code (you need to open your browser's console to see the error)

💻 Code

type EnvFunction = <T>() => T;

declare function using<T>(handler: () => T): T;

type SimpleType = string | Promise<SimpleType>;

declare const simple: SimpleType;

const env: EnvFunction = () => using(() => simple);

🙁 Actual behavior

TS crashes due to an infinitely recursive call

RangeError: Maximum call stack size exceeded
    at getAwaitedTypeNoAlias (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:68058:39)
    at mapType (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:58207:85)
    at getAwaitedTypeNoAlias (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:68071:60)
    at getAwaitedTypeNoAlias (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:68082:35)
    at mapType (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:58207:85)
    at getAwaitedTypeNoAlias (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:68071:60)
    at getAwaitedTypeNoAlias (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:68082:35)
    at mapType (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:58207:85)
    at getAwaitedTypeNoAlias (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:68071:60)
    at getAwaitedTypeNoAlias (/home/nic/Documents/dev/babel/babel/node_modules/typescript/lib/tsc.js:68082:35)

🙂 Expected behavior

Not crash, but maybe report a type error (since env returns SimpleType and not T).

For reference, this comes from some real-world code (that should be valid and not report a type error, but it was a too complex example to use in the issue description): https://github.com/babel/babel/blob/87f26d5a172dae8f6d81a86c9d831e60c99220fe/packages/babel-core/src/config/helpers/config-api.ts#L50-L68

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

Successfully merging a pull request may close this issue.

2 participants