Files
tsgo/testdata/baselines/reference/submodule/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.errors.txt

45 lines
2.0 KiB
Plaintext

genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts(13,5): error TS2322: Type 'ReturnType<T[M]>' is not assignable to type 'A'.
Type 'ReturnType<T[keyof T]>' is not assignable to type 'A'.
Type 'ReturnType<T[string | number | symbol]>' is not assignable to type 'A'.
Type 'ReturnType<T[string]> | ReturnType<T[number]> | ReturnType<T[symbol]>' is not assignable to type 'A'.
Type 'ReturnType<T[string]>' is not assignable to type 'A'.
Type 'ReturnType<FunctionsObj<T>[string]>' is not assignable to type 'A'.
Type 'unknown' is not assignable to type 'A'.
==== genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts (1 errors) ====
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;
~
!!! error TS2322: Type 'ReturnType<T[M]>' is not assignable to type 'A'.
!!! error TS2322: Type 'ReturnType<T[keyof T]>' is not assignable to type 'A'.
!!! error TS2322: Type 'ReturnType<T[string | number | symbol]>' is not assignable to type 'A'.
!!! error TS2322: Type 'ReturnType<T[string]> | ReturnType<T[number]> | ReturnType<T[symbol]>' is not assignable to type 'A'.
!!! error TS2322: Type 'ReturnType<T[string]>' is not assignable to type 'A'.
!!! error TS2322: Type 'ReturnType<FunctionsObj<T>[string]>' is not assignable to type 'A'.
!!! error TS2322: Type 'unknown' is not assignable to type 'A'.
}
// 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
}
}