File: assignmentNonObjectTypeConstraints.types

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (65 lines) | stat: -rw-r--r-- 949 bytes parent folder | download | duplicates (2)
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
=== tests/cases/compiler/assignmentNonObjectTypeConstraints.ts ===
const enum E { A, B, C }
>E : E
>A : E.A
>B : E.B
>C : E.C

function foo<T extends number>(x: T) {
>foo : <T extends number>(x: T) => void
>T : T
>x : T
>T : T

    var y: number = x;  // Ok
>y : number
>x : T
}

foo(5);
>foo(5) : void
>foo : <T extends number>(x: T) => void
>5 : 5

foo(E.A);
>foo(E.A) : void
>foo : <T extends number>(x: T) => void
>E.A : E.A
>E : typeof E
>A : E.A

class A { a }
>A : A
>a : any

class B { b }
>B : B
>b : any

function bar<T extends A | B>(x: T) {
>bar : <T extends A | B>(x: T) => void
>T : T
>A : A
>B : B
>x : T
>T : T

    var y: A | B = x;  // Ok
>y : A | B
>A : A
>B : B
>x : T
}

bar(new A);
>bar(new A) : void
>bar : <T extends A | B>(x: T) => void
>new A : A
>A : typeof A

bar(new B);
>bar(new B) : void
>bar : <T extends A | B>(x: T) => void
>new B : B
>B : typeof B