File: genericConstraint2.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 (72 lines) | stat: -rw-r--r-- 1,557 bytes parent folder | download | duplicates (4)
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
=== tests/cases/compiler/genericConstraint2.ts ===
interface Comparable<T> {
    comparer(other: T): number;
>comparer : (other: T) => number
>other : T
}

function compare<T extends Comparable<T>>(x: T, y: T): number {
>compare : <T extends Comparable<T>>(x: T, y: T) => number
>x : T
>y : T

    if (x == null) return y == null ? 0 : -1;
>x == null : boolean
>x : T
>null : null
>y == null ? 0 : -1 : 0 | -1
>y == null : boolean
>y : T
>null : null
>0 : 0
>-1 : -1
>1 : 1

    if (y == null) return 1;
>y == null : boolean
>y : T
>null : null
>1 : 1

    return x.comparer(y);
>x.comparer(y) : number
>x.comparer : (other: T) => number
>x : T
>comparer : (other: T) => number
>y : T
}

class ComparableString implements Comparable<string>{
>ComparableString : ComparableString

    constructor(public currentValue: string) { }
>currentValue : string

    localeCompare(other) {
>localeCompare : (other: any) => number
>other : any

        return 0;
>0 : 0
    }
}

var a = new ComparableString("a");
>a : ComparableString
>new ComparableString("a") : ComparableString
>ComparableString : typeof ComparableString
>"a" : "a"

var b = new ComparableString("b");
>b : ComparableString
>new ComparableString("b") : ComparableString
>ComparableString : typeof ComparableString
>"b" : "b"

var c = compare<ComparableString>(a, b);
>c : number
>compare<ComparableString>(a, b) : number
>compare : <T extends Comparable<T>>(x: T, y: T) => number
>a : ComparableString
>b : ComparableString