|
| 1 | +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts === |
| 2 | + |
| 3 | +type Kind = "A" | "B" |
| 4 | +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0)) |
| 5 | + |
| 6 | +interface Entity { |
| 7 | +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) |
| 8 | + |
| 9 | + kind: Kind; |
| 10 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18)) |
| 11 | +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0)) |
| 12 | +} |
| 13 | + |
| 14 | +interface A extends Entity { |
| 15 | +>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1)) |
| 16 | +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) |
| 17 | + |
| 18 | + kind: "A"; |
| 19 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 7, 28)) |
| 20 | + |
| 21 | + a: number; |
| 22 | +>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 8, 14)) |
| 23 | +} |
| 24 | + |
| 25 | +interface B extends Entity { |
| 26 | +>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1)) |
| 27 | +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) |
| 28 | + |
| 29 | + kind: "B"; |
| 30 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 12, 28)) |
| 31 | + |
| 32 | + b: string; |
| 33 | +>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 13, 14)) |
| 34 | +} |
| 35 | + |
| 36 | +// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid |
| 37 | +// interpreting respective overloads as "specialized" signatures. |
| 38 | +// That way, we can avoid the need to look for a compatible overload |
| 39 | +// signature and simply check compatibility with the implementation. |
| 40 | +function hasKind(entity: Entity, kind: "A" | "A"): entity is A; |
| 41 | +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) |
| 42 | +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17)) |
| 43 | +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) |
| 44 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 21, 32)) |
| 45 | +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17)) |
| 46 | +>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1)) |
| 47 | + |
| 48 | +function hasKind(entity: Entity, kind: "B" | "B"): entity is B; |
| 49 | +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) |
| 50 | +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17)) |
| 51 | +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) |
| 52 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 22, 32)) |
| 53 | +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17)) |
| 54 | +>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1)) |
| 55 | + |
| 56 | +function hasKind(entity: Entity, kind: Kind): entity is Entity { |
| 57 | +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) |
| 58 | +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17)) |
| 59 | +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) |
| 60 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32)) |
| 61 | +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0)) |
| 62 | +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17)) |
| 63 | +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) |
| 64 | + |
| 65 | + return entity.kind === kind; |
| 66 | +>entity.kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18)) |
| 67 | +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17)) |
| 68 | +>kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18)) |
| 69 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32)) |
| 70 | +} |
| 71 | + |
| 72 | +let x: A = { |
| 73 | +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) |
| 74 | +>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1)) |
| 75 | + |
| 76 | + kind: "A", |
| 77 | +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 27, 12)) |
| 78 | + |
| 79 | + a: 100, |
| 80 | +>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 28, 14)) |
| 81 | +} |
| 82 | + |
| 83 | +if (hasKind(x, "A")) { |
| 84 | +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) |
| 85 | +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) |
| 86 | + |
| 87 | + let a = x; |
| 88 | +>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 33, 7)) |
| 89 | +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) |
| 90 | +} |
| 91 | +else { |
| 92 | + let b = x; |
| 93 | +>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 36, 7)) |
| 94 | +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) |
| 95 | +} |
| 96 | + |
| 97 | +if (!hasKind(x, "B")) { |
| 98 | +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) |
| 99 | +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) |
| 100 | + |
| 101 | + let c = x; |
| 102 | +>c : Symbol(c, Decl(stringLiteralTypesAsTags03.ts, 40, 7)) |
| 103 | +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) |
| 104 | +} |
| 105 | +else { |
| 106 | + let d = x; |
| 107 | +>d : Symbol(d, Decl(stringLiteralTypesAsTags03.ts, 43, 7)) |
| 108 | +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) |
| 109 | +} |
0 commit comments