Skip to content

Stack overflow with incorrect mapped type as constraint of type parameter #17847

Description

function sum<T extends { [P in T]: number }, K extends keyof T>() {
    n += v[k];
}

This incorrect code puts the compiler in an infinite loop:

     RangeError: Maximum call stack size exceeded
      at Object.contains (src/compiler/core.ts:276:5)
      at getBaseConstraint (src/compiler/checker.ts:5955:21)
      at getResolvedBaseConstraint (src/compiler/checker.ts:5949:36)
      at hasNonCircularBaseConstraint (src/compiler/checker.ts:5936:20)
      at getConstraintOfTypeParameter (src/compiler/checker.ts:5906:20)
      at getConstraintTypeFromMappedType (src/compiler/checker.ts:5761:56)
      at isGenericMappedType (src/compiler/checker.ts:5798:84)
      at computeBaseConstraint (src/compiler/checker.ts:5997:21)
      at getBaseConstraint (src/compiler/checker.ts:5960:32)
      at computeBaseConstraint (src/compiler/checker.ts:5969:38)
      at getBaseConstraint (src/compiler/checker.ts:5960:32)

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions