Skip to content
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

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

Closed
nodkz opened this issue May 3, 2019 · 5 comments · Fixed by #37327
Closed

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

nodkz opened this issue May 3, 2019 · 5 comments · Fixed by #37327
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fixed A PR has been merged for this issue

Comments

@nodkz
Copy link

nodkz commented May 3, 2019

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:

> ts-max-call-stack@1.0.0 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
@weswigham weswigham added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels May 8, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.6.0 milestone Jun 12, 2019
orta pushed a commit to orta/TypeScript that referenced this issue Jun 17, 2019
orta pushed a commit to orta/TypeScript that referenced this issue Jul 31, 2019
@nodkz
Copy link
Author

nodkz commented Oct 23, 2019

@orta, please help to fix this issue. It blocks me from upgrading Gatsby and other small projects.

Thanks.

@RobinTail
Copy link

I have the same issue on TypeScript v3.6.4

@IgorSzymanski
Copy link

Same issue on TS 3.7.2.

@nodkz
Copy link
Author

nodkz commented Nov 25, 2019

As a workaround I relaxed the checks in my lib:

export type ObjMapReadOnly<T> = Readonly<{ [key: string]: Readonly<T> }>;
- export type Thunk<T> = (() => T) | T;
+ export type Thunk<T> = (() => any) | 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;
}

It's better than nothing "maximum call stack size exceeded"

photo_2019-11-25 12 21 30

nodkz added a commit to graphql-compose/graphql-compose that referenced this issue Nov 25, 2019
nodkz added a commit to graphql-compose/graphql-compose that referenced this issue Dec 11, 2019
@RyanCavanaugh
Copy link
Member

Possible alternative repro #35804

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fixed A PR has been merged for this issue
Projects
None yet
8 participants