Closed
Description
TypeScript Version: 4.1.2
Search Terms: CFA, narrowing, generic, mapped type, conditional type, type assertion
Code
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]>) {
if (isA(a2)) {
// a2 is not narrowed
a2.x // error, but should be ok
}
}
Expected behavior:
Type of a2
should be narrowed to ReturnType<T[M]> & A
It works this way in TS 4.0
Actual behavior:
Type of a2
remains only ReturnType<T[M]>