Skip to content

Maximum call stack size exceeded #14723

Closed

Description

TypeScript Version: 2.2.1 / nightly 2.3.0-dev.20170318

The smallest code I got that produces the issue is:

class Component<S> {
    setState<K extends keyof S>(state: Pick<S, K>) {}
}

export interface State<T> {
    a?: T;
}

class Foo {}

class Comp<T extends Foo, S> extends Component<S & State<T>>
{
    foo() {
        const a:T = {};
        this.setState({ a: a });
    }
}

Throws:

RangeError: Maximum call stack size exceeded
    at getConstraintFromTypeParameter (D:\...\node_modules\typescript\lib\tsc.js:24863:48)
    at getConstraintOfTypeParameter (D:\...node_modules\typescript\lib\tsc.js:24268:66)
    at isRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26681:42)
    at isRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26665:38)
    at typeArgumentsRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26904:35)
    at isRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26706:38)
    at isRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26688:42)
    at isRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26665:38)
    at typeArgumentsRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26904:35)
    at isRelatedTo (D:\...\node_modules\typescript\lib\tsc.js:26706:38)

No configuration required.
Windows / Node 7.7.3

Activity

  1. jamesknelson commented on Mar 21, 2017

    @jamesknelson

    Think I've got a similar issue, based on the stack trace. I've managed to get the offending code down to this:

    type Attributes<Keys extends string> = {
        [Key in Keys]: string; // I'm actually using Attribute<Key> in my code, but `string` is all that is needed to cause the RangeError
    }
    
    class Query<A extends Attributes<keyof A>> {
        multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>;
    }

    Stack trace:

    /usr/local/lib/node_modules/typescript/lib/tsc.js:51296
                    throw e;
                    ^
    
    RangeError: Maximum call stack size exceeded
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26081:33)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26166:38)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26139:42)
        at typeRelatedToEachType (/usr/local/lib/node_modules/typescript/lib/tsc.js:26351:35)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26125:34)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26189:42)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26147:38)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26153:38)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26153:38)
        at isRelatedTo (/usr/local/lib/node_modules/typescript/lib/tsc.js:26153:38)
    

    I'm on tsc 2.2.1, node 7.7.2, osx 10.11.6

  2. added
    BugA bug in TypeScript
    and removed
    BugA bug in TypeScript
    on Mar 24, 2017
  3. ahejlsberg commented on Mar 27, 2017

    @ahejlsberg
    Member

    James K Nelson (@jamesknelson) The issue you're seeing above isn't related to this one (and isn't fixed by #14874). Would you mind creating a new issue.

  4. locked and limited conversation to collaborators on Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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