File: assignmentNonObjectTypeConstraints.types

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (57 lines) | stat: -rw-r--r-- 889 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
45
46
47
48
49
50
51
52
53
54
55
56
57
=== 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
>x : 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
>x : T

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

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