TypeScript/tests/baselines/reference/genericTypeAssertions6.errors.txt

42 lines
2.6 KiB
Plaintext

tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2352: Conversion of type 'U' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
'T' could be instantiated with an arbitrary type which could be unrelated to 'U'.
tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2352: Conversion of type 'T' to type 'U' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Conversion of type 'U' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'.
==== tests/cases/compiler/genericTypeAssertions6.ts (3 errors) ====
class A<T,U> {
constructor(x) {
var y = <T>x;
var z = <U>x;
}
f(x: T, y: U) {
x = <T>y;
~~~~
!!! error TS2352: Conversion of type 'U' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'.
y = <U>x;
~~~~
!!! error TS2352: Conversion of type 'T' to type 'U' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
}
}
class B<T extends Date, U extends Date> extends A<T, U> {
g(x: T) {
var a: Date = x;
var b = <Date>x;
var c = <T>new Date();
var d = <U>new Date();
var e = <T><U>new Date();
~~~~~~~~~~~~~~~~
!!! error TS2352: Conversion of type 'U' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'.
}
}
var b: B<Date, Date>;
var c: A<Date, Date> = <A<Date, Date>>b;