Skip to content

Maximum call stack size exceeded #14896

Closed

Description

TypeScript Version: 2.2.1

Note that this is a separate bug from #14723 and is not fixed by #14874 as noted by Anders Hejlsberg (@ahejlsberg)

Code

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>;
}

Expected behavior:

Should compile

Actual behavior:

Fails to compile with 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)

Activity

  1. akaRem commented on Mar 28, 2017

    @akaRem

    Hi, James K Nelson (@jamesknelson) !
    I wonder how you use this type.

    I've tried it on playground, and found such valid case:

    type Attributes<Keys extends string> = {
        [Key in Keys]: string;
    }
    
    function f (x: Attributes<'ab'>): string {
        return x.ab
    }

    It doesn't allow to pass anything except just 1 string to Attributes and exposes that string as only valid attribute.

  2. jamesknelson commented on Mar 30, 2017

    @jamesknelson
    Author

    Ivan (@akaRem) The code I added to this issue is not really that useful, it is just the minimal code I could find that causes the bug.

    My actual Attributes class has a set of Attribute<Key> objects, as opposed to the string values in the example. I use it to model the response of an API.

  3. 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