612c92d603
* Track source and target relationship stack depth seperately, only increase on change in value * Add baselines for test from #43485 * Bail on unwrapping conditional constraints on the source side when the source conditional is already known to be spooling out of control * More usage of isDeeplyNestedType to block _specifically_ conditional recursion on only one side * Negative cases of getNarrowedType that match the exact type should be filtered out, even when generic * Add test and fix for #44404 * Swap to manually specifying left and right recursion * Rename Left -> Source, Right -> Target Co-authored-by: Andrew Branch <andrew@wheream.io>
53 lines
1.1 KiB
Plaintext
53 lines
1.1 KiB
Plaintext
=== tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts ===
|
|
interface A { x: number }
|
|
>x : number
|
|
|
|
declare function isA(a: unknown): a is A;
|
|
>isA : (a: unknown) => a is A
|
|
>a : unknown
|
|
|
|
type FunctionsObj<T> = {
|
|
>FunctionsObj : FunctionsObj<T>
|
|
|
|
[K in keyof T]: () => unknown
|
|
}
|
|
|
|
function g<
|
|
>g : <T extends FunctionsObj<T>, M extends keyof T>(a2: ReturnType<T[M]>, x: A) => void
|
|
|
|
T extends FunctionsObj<T>,
|
|
M extends keyof T
|
|
>(a2: ReturnType<T[M]>, x: A) {
|
|
>a2 : ReturnType<T[M]>
|
|
>x : A
|
|
|
|
x = a2;
|
|
>x = a2 : ReturnType<T[M]>
|
|
>x : A
|
|
>a2 : ReturnType<T[M]>
|
|
}
|
|
|
|
// Original CFA report of the above issue
|
|
|
|
function g2<
|
|
>g2 : <T extends FunctionsObj<T>, M extends keyof T>(a2: ReturnType<T[M]>) => void
|
|
|
|
T extends FunctionsObj<T>,
|
|
M extends keyof T
|
|
>(a2: ReturnType<T[M]>) {
|
|
>a2 : ReturnType<T[M]>
|
|
|
|
if (isA(a2)) {
|
|
>isA(a2) : boolean
|
|
>isA : (a: unknown) => a is A
|
|
>a2 : ReturnType<T[M]>
|
|
|
|
// a2 is not narrowed
|
|
a2.x // error, but should be ok
|
|
>a2.x : number
|
|
>a2 : ReturnType<T[M]> & A
|
|
>x : number
|
|
}
|
|
}
|
|
|