Skip to content

Stack overflow error when using inline mapped tuplesΒ #53458

Closed
@danny-may

Description

@danny-may

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions