File: genericTypeAssertions6.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (44 lines) | stat: -rw-r--r-- 2,967 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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'.
!!! related TS2208 tests/cases/compiler/genericTypeAssertions6.ts:1:11: This type parameter might need an `extends T` constraint.
            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'.
!!! related TS2208 tests/cases/compiler/genericTypeAssertions6.ts:1:9: This type parameter might need an `extends U` constraint.
        }
    }
    
    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;