microsoft / TypeScript Public
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
4.7 regression: Array.flat(infinity) leads to "Type instantiation is excessively deep and possibly infinite." error #49280
Comments
|
Ran into this today as well in 4.7.2. 4.6 typed the output as |
|
also ran into this in an upgrade from 4.6.4 to 4.7.2. Entire app won't compile as a result. |
|
Just ran into this as well, here's a very concise example: Same exact error on A quick solution for now is to assert your
Should make the error go away. |
|
I'm not quite sure how to reason about this. This error is, for all intents and purposes, correct. You could have written interface Config {
prop?: string;
}
interface ExtendedConfig extends Config {}
type NestedConfigs = Array<ExtendedConfig | NestedConfigs>;
const configs: NestedConfigs[] = [];
configs.push(configs); // <- legal
const flattened = configs.flat(Infinity); // <- crashes at runtimewhich causes If you have a finitely-deep (T | T[])[] then it seems best to pass a finite argument to |
|
I'm not sure what I think the correct type of the output is, but it does seem to me that the TypeScript compiler should allow Maybe it would make sense to special-case |
|
I should also note that, as a user of TypeScript, the "possibly infinite" thing made enough sense to me, but I was a bit stumped how to get around the type error because this kind of error prevents doing a post-cast like |
Oh, that's really interesting, I actually didn't know that. So to get more specific, in my use case I was actually using it within a function that allows one to optionally declare a flattening depth. To go off of my example, that might look like: The intent here was to mimic something like a I tend to agree with @grant-dennison above, it seems like A potential middle-ground here may be some form of 'non-infinite' integer or number type. To go back to my example: That way I can tell TypeScript that this is actually bounded by some unknowably-high integer, and have type errors if I try to call |
|
This could be addressed if a literal type for |
Bug Report
TypeScript Workbench with relevant code
TypeScript raises the following error for the
configs.flat(Infinity)call:Type instantiation is excessively deep and possibly infinite. ts(2589)No error should be raised.
The text was updated successfully, but these errors were encountered: