Skip to content

[TSC fails] RangeError: Maximum call stack size exceeded [with repro repo] #31230

Closed
@nodkz

Description

@nodkz

TypeScript Version: Version 3.5.0-dev.20190503

Search Terms:

tsc, RangeError, Maximum call stack size exceeded

Code

import { ObjectTypeComposer } from 'graphql-compose';
declare const User: ObjectTypeComposer<any, any>;
User.addResolver({ type: User });

Dramatically simplified graphql-compose.d.ts:

export type ObjMapReadOnly<T> = Readonly<{ [key: string]: Readonly<T> }>;
export type Thunk<T> = (() => T) | T;

export type ComposeOutputTypeDefinition = Readonly<ObjectTypeComposer<any, any> | EnumTypeComposer>;

export class EnumTypeComposer {
  public setFields(fields: { [name: string]: { [key: string]: any } }): this;
}

export class ObjectTypeComposer<TSource, TContext> {
  public setFields(fields: ObjMapReadOnly<Resolver>): this;

  public addResolver<TResolverSource>(opts: { type?: Thunk<ComposeOutputTypeDefinition> }): this;
}

export class Resolver {
  public wrapArgs<NewContext>(
    cb: () => {
      [argName: string]: Thunk<Readonly<EnumTypeComposer>>;
    }
  ): void;

  public wrapType(cb: () => ComposeOutputTypeDefinition): void;
}

Expected behavior:

Do not fall with Maximum call stack size exceeded error.

Actual behavior:

> [email protected] tsc /Users/nodkz/www/_sandbox/nodkz-tsc-problem
> tsc

/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:72973
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at __generator (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:30:13)
    at getUnmatchedProperties (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37203:20)
    at getUnmatchedProperty (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37237:20)
    at typesDefinitelyUnrelated (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37245:19)
    at inferFromObjectTypes (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37544:22)
    at inferFromTypes (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37456:29)
    at inferFromContravariantTypes (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37475:21)
    at applyToParameterTypes (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37047:17)
    at inferFromSignature (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37603:21)
    at inferFromSignatures (/Users/nodkz/www/_sandbox/nodkz-tsc-problem/node_modules/typescript/lib/tsc.js:37595:21)

Playground Link:

Simplified repro repo: https://github.com/nodkz/tsc-problem

git clone https://github.com/nodkz/tsc-problem ./nodkz-tsc-problem \
  && cd nodkz-tsc-problem \
  && npm install \
  && npm run tsc

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions