File: typeParameterAssignability3.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (81 lines) | stat: -rw-r--r-- 1,259 bytes parent folder | download | duplicates (5)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
=== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability3.ts ===
// type parameters are not assignable to one another unless directly or indirectly constrained to one another

class Foo { foo: string; }
>Foo : Foo
>foo : string

function foo<T extends Foo, U extends Foo>(t: T, u: U) {
>foo : <T extends Foo, U extends Foo>(t: T, u: U) => void
>t : T
>u : U

    var a: T;
>a : T

    var b: U;
>b : U

    t = a; // ok
>t = a : T
>t : T
>a : T

    a = t; // ok
>a = t : T
>a : T
>t : T

    b = u; // ok
>b = u : U
>b : U
>u : U

    u = b; // ok
>u = b : U
>u : U
>b : U

    t = u; // error
>t = u : U
>t : T
>u : U

    u = t; // error
>u = t : T
>u : U
>t : T
}

class C<T extends Foo, U extends Foo> {
>C : C<T, U>

    t: T;
>t : T

    u: U;
>u : U

    r = () => {
>r : () => void
>() => {        this.t = this.u; // error        this.u = this.t; // error    } : () => void

        this.t = this.u; // error
>this.t = this.u : U
>this.t : T
>this : this
>t : T
>this.u : U
>this : this
>u : U

        this.u = this.t; // error
>this.u = this.t : T
>this.u : U
>this : this
>u : U
>this.t : T
>this : this
>t : T
    }
}