Skip to content

Stack overflow while type checking generic, mutually-defined function interfaces #18277

@willfrew

Description

@willfrew

TypeScript Version: 2.4.0 onwards

Code

export interface Foo<T> {
  (bar: Bar<T>): void;
}

export interface Bar<T> {
  (foo: Foo<T>): Foo<T>;
}

function createBar<T>(): Bar<T> {
  return (f) => f;
}

function foo<T>(
  bar: Bar<T>,
): void {}

// Stack overflow
createBar()(foo) === foo;

Simplified down from a real code-base.

Expected behavior:

Compiles fine, as per < 2.3.4

Actual behavior:

With 2.4.0 (same behaviour with 2.5.2):

$ ./node_modules/.bin/tsc example.ts
./node_modules/typescript/lib/tsc.js:55708
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at getErasedSignature (.../node_modules/typescript/lib/tsc.js:27019:36)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28517:22)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)
    at compareSignaturesRelated (.../node_modules/typescript/lib/tsc.js:28548:21)

Metadata

Metadata

Assignees

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