Skip to content

Stack overflow error when using inline mapped tuples #53458

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
danny-may opened this issue Mar 23, 2023 · 6 comments Β· Fixed by #53522
Closed

Stack overflow error when using inline mapped tuples #53458

danny-may opened this issue Mar 23, 2023 · 6 comments Β· Fixed by #53522
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@danny-may
Copy link

danny-may commented Mar 23, 2023

Bug Report

πŸ”Ž Search Terms

Maximum call stack size exceeded
getMappedType

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions 4.6.4 and 4.7.4

⏯ Playground Link

Playground link with relevant code

This is an example of a logically identical class, with the inline mapping extracted, where the compiler doesnt crash

πŸ’» Code

class Foo<Elements extends readonly unknown[]> {
    public readonly elements: { [P in keyof Elements]: { bar: Elements[P]; } };

    public constructor(...elements: { [P in keyof Elements]: { bar: Elements[P] } }) {
        this.elements = elements;
    }

    public add(): Foo<[...Elements, 'abc']> {
        return new Foo<[...Elements, 'abc']>(...this.elements, { bar: 'abc' });
    }
}

πŸ™ Actual behavior

The compiler crashes with a stack overflow error
image

πŸ™‚ Expected behavior

Compilation should succeed with no errors. Extracting the inline mapped type to its own type definition achieves this, but the two are logically identical so the stack overflow is unexpected.

@fatcerberus
Copy link

fatcerberus commented Mar 23, 2023

You maniac! You blew it up! Damn you!
πŸ˜†

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Mar 23, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 23, 2023
@RyanCavanaugh
Copy link
Member

This has been an issue since 4.0.5

Strong contender for the "crash which was oldest at the point it was first found" award of 2023.

Let me know if you're actually blocked by this (sounds like no?) and if so I'll assign it out instead of backlog.

@danny-may
Copy link
Author

Not blocked by this, giving a name to the mapped type seems to fix this for whatever reason and to be honest ends up being more readable than having it inline. I just noticed this while doing some quick prototyping and was very confused as to why vscode stopped giving me errors all of a sudden.

@Andarist
Copy link
Contributor

Andarist commented Mar 23, 2023

A more detailed call stack for those who might be interested where this happens :P
call stack leading to getMappedType and ultimately to a crash

@danny-may
Copy link
Author

Damn, I did some more playing and it looks like this has only been an issue since 4.7.4. Looks like changing versions in the playground doesnt cause errors to appear immediately. There goes my award 😒

@fatcerberus
Copy link

Normally that takes effect immediately, but since this is actually crashing the compiler, it might be taking longer to recover from or something.

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
4 participants