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

RangeError when trying to infer type for Array.prototype.flat() #38298

Closed
0kku opened this issue May 2, 2020 · 4 comments · Fixed by #38904
Closed

RangeError when trying to infer type for Array.prototype.flat() #38298

0kku opened this issue May 2, 2020 · 4 comments · Fixed by #38904
Assignees
Labels
Bug A bug in TypeScript

Comments

@0kku
Copy link

0kku commented May 2, 2020

TypeScript Version: 3.9.1-rc, 4.0.0-dev.20200430

Search Terms: Array flat RangeError Maximum call stack size exceeded

Code

class Foo <T> {
  arr: T[] = [];
    
  bar (
    depth = 1,
  ) {
    return this.arr.flat(depth);
  }
}

Expected behavior:
Code compiles without errors.

Actual behavior:
TSC crashes with RangeError: Maximum call stack size exceeded. Edit: Only happens when either --watch or --declaration flag is set.

Playground Link: Couldn't figure out how to add newer libs for Array, and not super useful anyway, as the compiler crashes

Related Issues:
#32131 seems to be the breaking PR
#36554 seems related maybe

edit: simplified code example

@b-fuze
Copy link

b-fuze commented May 2, 2020

I can also produce it here

function foo<T>(arr: T[], depth: number) {
  return arr.flat(depth);
}

And this compiles fine

function foo<T>(arr: T[]) {
  return arr.flat(5);
}

But this does not

function foo<T>(arr: T[]) {
  return arr.flat(<number> 5);
}

And this is the tsc (4.0.0-dev.20200501) command:

tsc flat-test.ts --lib es2019 -m ESNext -t ESNEXT -w

Edit: After corresponding with @0kku he discovered it also happens with --declaration

tsc flat-test.ts --lib es2019 -m ESNext -t ESNEXT --declaration

@millsp
Copy link
Contributor

millsp commented May 2, 2020

Not able to reproduce the error on 3.9.1-rc or 4.0.0-dev.20200430. Compiles.

@b-fuze
Copy link

b-fuze commented May 2, 2020

@pirix-gh It doesn't happen in normal mode, it happens in watch mode.

@0kku
Copy link
Author

0kku commented May 2, 2020

Looks like it doesn't happen if I comment out "declaration": true from my tsconfig. Also with -w flag it happens regardless of that config option. Here's my tsconfig:

{
  "compilerOptions": {
    "lib": ["es2019"],
    "declaration": true,
    "outDir": "./dist",
    "rootDir": "./src",
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
5 participants