Skip to content
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

RangeError: Maximum call stack size exceeded on recursive conditional type with template literal string type using infer keyword #53783

Closed
DetachHead opened this issue Apr 15, 2023 · 1 comment Β· Fixed by #53801
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@DetachHead
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

RangeError: Maximum call stack size exceeded

πŸ•— Version & Regression Information

5.1.0-dev.20230414

⏯ Playground Link

Playground link with relevant code

(check the console for the error)

πŸ’» Code

type LengthDown<
  Str extends string,
  Length extends number | bigint,
  It
> = It extends StrIter.Iterator
  ? StrIter.CutAt<Str, It> extends `${infer $Rest}`
    ? LengthDown<$Rest, Add<Length, StrIter.Value<It>>, It>
    : LengthDown<Str, Length, StrIter.Prev<It>>
  : Length;

πŸ™ Actual behavior

> tsc --noEmit --moduleresolution nodenext

C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:114339
      throw e;
      ^

RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>)
    at formatStringFromArgs (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:15925:15)
    at createFileDiagnostic (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:15999:12)
    at createDiagnosticForNodeInSourceFile (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:12335:10)
    at createDiagnosticForNode (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:12327:10)
    at createError (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:43554:23)
    at error (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:43557:24)
    at C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:44396:15
    at addLazyDiagnostic (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:79812:33)
    at resolveNameHelper (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:44359:9)

πŸ™‚ Expected behavior

no crash

@DetachHead
Copy link
Contributor Author

here's a more minimal example:

type Foo<T> = T extends unknown
  ? unknown extends `${infer $Rest}`
    ? Foo<T>
    : Foo<unknown>
  : unknown;

but the stack trace is slightly different, so i'm not sure if it's the exact same issue:

RangeError: Maximum call stack size exceeded
    at resolveNameHelper (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:44106:29)
    at resolveName (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:44104:12)
    at resolveEntityName (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:45554:32)
    at getSymbolOfNameOrPropertyAccessExpression (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:80179:22)
    at getSymbolAtLocation (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:80264:18)
    at getTypeFromTypeNodeWorker (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:57735:24)
    at containsReference (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:57960:101)
    at visitNode2 (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:25417:18)
    at forEachChildInTypeReference (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:25523:12)
    at forEachChild (C:\Users\user\hotscript\node_modules\typescript\lib\tsc.js:25931:35)

@DetachHead DetachHead changed the title RangeError: Maximum call stack size exceeded on recursive conditional type with template literal string type RangeError: Maximum call stack size exceeded on recursive conditional type with template literal string type using infer keyword Apr 15, 2023
@ahejlsberg ahejlsberg self-assigned this Apr 16, 2023
@ahejlsberg ahejlsberg added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Apr 16, 2023
@ahejlsberg ahejlsberg added this to the TypeScript 5.1.0 milestone Apr 16, 2023
@ahejlsberg ahejlsberg added the Fix Available A PR has been opened for this issue label Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue
Projects
None yet
2 participants