-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Maximum call stack size exceeded while inferring conditional type. #22950
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
Comments
I am not sure why you are writing a constraint this way, it seems to me that this should just be |
Agreed the code isn’t meaningful at all. I was in the process of writing something longer that wouldn’t have been so pointless when I stumbled onto this crash and figured the crash was a bug regardless of the code. |
constraining a generic type of a mapped type on itself is not that useful of a patter i would say. |
You'd be surprised then. I've been using the pattern to successfully create compile errors if duplicate keys are found in an api that shouldn't accept duplicates. Simple-ish example I came up with from #22679: type ArrayKeys = keyof any[]
type Indices<T> = Exclude<keyof T, ArrayKeys>
type GetUnionKeys<U> = U extends Record<infer K, any> ? K : never
type CombineUnion<U> = { [K in GetUnionKeys<U>]: U extends Record<K, infer T> ? T : never }
type Combine<T> = CombineUnion<T[Indices<T>]>
declare function combine2<
T extends object[] &
{
[K in Indices<T>]: {
[K2 in keyof T[K]]: K2 extends GetUnionKeys<T[Exclude<Indices<T>, K>]> ? never : any
}
} & { "0": any }
>(objectsToCombine: T): Combine<T>
const result2 = combine2([{ foo: 534 }, { bar: "test" }])
// in TS 2.8 result2 has type {foo: number, bar: string}
const error2 = combine2([{ foo: 534, dupKey: "dup1" }, { bar: "test", dupKey: "dup2" }])
// Actually has an error here as intended because of dupKey in both objects And it's not ready for anyone to use or even really read yet but I've been experimenting with more complicated use cases that might end up being very practical: Example |
Here's a meaningful case that triggers
|
Update: I believe this bug has been fixed in 2.9.1 insiders build. |
TypeScript Version: 2.9.0-dev.20180328
The code below fails with a "Maximum call stack size exceeded" error. I actually came across this while trying to make a minimal example of a separate problem which is why the code looks so useless.
Code
Additional similar case that started crashing later. Following code does not crash in 2.8.1 but does in typescript@next
Actual behavior:
Playground Link:
Link
Related Issues:
Multiple "Maximum call stack size exceeded" issues exist but looking at the recent ones I did not notice any that were obvious duplicates.
The text was updated successfully, but these errors were encountered: