File: stringLiteralTypesTypePredicates01.js

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 (49 lines) | stat: -rw-r--r-- 892 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
//// [stringLiteralTypesTypePredicates01.ts]
type Kind = "A" | "B"

function kindIs(kind: Kind, is: "A"): kind is "A";
function kindIs(kind: Kind, is: "B"): kind is "B";
function kindIs(kind: Kind, is: Kind): boolean {
    return kind === is;
}

var x: Kind = undefined;

if (kindIs(x, "A")) {
    let a = x;
}
else {
    let b = x;
}

if (!kindIs(x, "B")) {
    let c = x;
}
else {
    let d = x;
}

//// [stringLiteralTypesTypePredicates01.js]
function kindIs(kind, is) {
    return kind === is;
}
var x = undefined;
if (kindIs(x, "A")) {
    var a = x;
}
else {
    var b = x;
}
if (!kindIs(x, "B")) {
    var c = x;
}
else {
    var d = x;
}


//// [stringLiteralTypesTypePredicates01.d.ts]
declare type Kind = "A" | "B";
declare function kindIs(kind: Kind, is: "A"): kind is "A";
declare function kindIs(kind: Kind, is: "B"): kind is "B";
declare var x: Kind;