TypeScript/tests/baselines/reference/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.js
Wesley Wigham 612c92d603
Track source and target relationship stack depth seperately, only increase on change in value (#41821)
* 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>
2021-09-30 16:58:40 -07:00

41 lines
840 B
TypeScript

//// [genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts]
interface A { x: number }
declare function isA(a: unknown): a is A;
type FunctionsObj<T> = {
[K in keyof T]: () => unknown
}
function g<
T extends FunctionsObj<T>,
M extends keyof T
>(a2: ReturnType<T[M]>, x: A) {
x = a2;
}
// Original CFA report of the above issue
function g2<
T extends FunctionsObj<T>,
M extends keyof T
>(a2: ReturnType<T[M]>) {
if (isA(a2)) {
// a2 is not narrowed
a2.x // error, but should be ok
}
}
//// [genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.js]
function g(a2, x) {
x = a2;
}
// Original CFA report of the above issue
function g2(a2) {
if (isA(a2)) {
// a2 is not narrowed
a2.x; // error, but should be ok
}
}