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

Maximum call stack size exceeded #14896

Closed
jamesknelson opened this issue Mar 28, 2017 · 2 comments
Closed

Maximum call stack size exceeded #14896

jamesknelson opened this issue Mar 28, 2017 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@jamesknelson
Copy link

TypeScript Version: 2.2.1

Note that this is a separate bug from #14723 and is not fixed by #14874 as noted by @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)
@akaRem
Copy link

akaRem commented Mar 28, 2017

Hi, @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.

@mhegazy mhegazy added the Bug A bug in TypeScript label Mar 28, 2017
@mhegazy mhegazy added this to the TypeScript 2.3 milestone Mar 28, 2017
@jamesknelson
Copy link
Author

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

@ahejlsberg ahejlsberg assigned ahejlsberg and unassigned sandersn Apr 3, 2017
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Apr 3, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants