Skip to content

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

@DetachHead

Description

@DetachHead

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions