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

4.5.0 regression - Maximum call stack size exceeded with recursive conditional types #46316

Closed
DetachHead opened this issue Oct 12, 2021 · 2 comments Β· Fixed by #46326
Closed

4.5.0 regression - Maximum call stack size exceeded with recursive conditional types #46316

DetachHead opened this issue Oct 12, 2021 · 2 comments Β· Fixed by #46326
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

maximum call stack size exceeded

πŸ•— Version & Regression Information

4.5.0-dev.20211012

  • This changed between versions 4.4.3 and 4.5.0-beta

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type _PrependNextNum<A extends Array<unknown>> = A['length'] extends infer T
    ? [T, ...A] extends [...infer X] 
        ? X
        : never
    : never
type _Enumerate<A extends Array<unknown>, N extends number> = N extends A['length']
    ? A
    : _Enumerate<_PrependNextNum<A>, N> & number

export type Enumerate<N extends number> = number extends N
    ? number
    : _Enumerate<[], N> extends (infer E)[]
    ? E
    : never

declare function foo<T extends unknown[]>(value: T): Enumerate<T['length']> {
    return value.length
}

πŸ™ Actual behavior

image

πŸ™‚ Expected behavior

no crash

@DetachHead DetachHead changed the title Maximum call stack size exceeded with recursive conditional types 5.5.0 regression - Maximum call stack size exceeded with recursive conditional types Oct 12, 2021
@DetachHead DetachHead changed the title 5.5.0 regression - Maximum call stack size exceeded with recursive conditional types 4.5.0 regression - Maximum call stack size exceeded with recursive conditional types Oct 12, 2021
@ahejlsberg
Copy link
Member

@weswigham Another one caused by #41821, basically a duplicate of #46183. Issue again is an infinitely expanding recursive conditional type that should relate as Ternary.Maybe after five levels.

@ahejlsberg ahejlsberg self-assigned this Oct 12, 2021
@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 Oct 12, 2021
@ahejlsberg ahejlsberg added this to the TypeScript 4.5.0 milestone Oct 12, 2021
@weswigham
Copy link
Member

Well, first problem is that we're actually stacking out rather than reporting the "infinitely expanding type" error. That would seem to imply that we're not incrementing the depth counter enough somewhere. Though, yes, once that's fixed, it is likely a duplicate of the other.

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
Development

Successfully merging a pull request may close this issue.

4 participants