Skip to content

Maximum call stack size exceeded from getResolvedBaseConstraint #14940

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

Closed
aaronbeall opened this issue Mar 30, 2017 · 1 comment
Closed

Maximum call stack size exceeded from getResolvedBaseConstraint #14940

aaronbeall opened this issue Mar 30, 2017 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@aaronbeall
Copy link

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)

Code

I'm probably doing something stupid here but I can't quite wrap my mind around it and the compiler just crashes:

type ClassName<S> = keyof S;
type ClassNameMap<S> = { [K in keyof S]?: boolean }
type ClassNameObjectMap<S> = object & ClassNameMap<S>; // protects against passing non-objects, but breaks index lookups 
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;

export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string {
  const args = classNames.map(arg => {
    if (arg == null) {
      return null;
    }
    if (typeof arg == "string") {
      return styles[arg];
    }
    if (typeof arg == "object") {
      return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
        const exportedClassName = styles[key];
        obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; 
        return obj;
      }, {});
    }
  });

  // return classnamer(...args);
  return "";
}

If I comment out the whole function body the errors go away.

Expected behavior:

No error, type S constrained to objects with only string properties and index lookups don't break.

Actual behavior:

Compiler fails with:

Process: Error processing message: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded
    at isSimpleTypeRelatedTo (evalmachine.<anonymous>:28208:39)
    at isRelatedTo (evalmachine.<anonymous>:28354:21)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
    at isRelatedTo (evalmachine.<anonymous>:28413:38)
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 30, 2017
@ahejlsberg
Copy link
Member

This looks to be the same issue as #14896.

@ahejlsberg ahejlsberg self-assigned this Apr 3, 2017
@ahejlsberg ahejlsberg added this to the TypeScript 2.3 milestone 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

4 participants