|
| 1 | +tests/cases/compiler/inKeywordTypeguard.ts(6,11): error TS2339: Property 'b' does not exist on type 'A'. |
| 2 | +tests/cases/compiler/inKeywordTypeguard.ts(8,11): error TS2339: Property 'a' does not exist on type 'B'. |
| 3 | +tests/cases/compiler/inKeywordTypeguard.ts(14,11): error TS2339: Property 'b' does not exist on type 'A'. |
| 4 | +tests/cases/compiler/inKeywordTypeguard.ts(16,11): error TS2339: Property 'a' does not exist on type 'B'. |
| 5 | +tests/cases/compiler/inKeywordTypeguard.ts(27,11): error TS2339: Property 'b' does not exist on type 'AWithOptionalProp | BWithOptionalProp'. |
| 6 | + Property 'b' does not exist on type 'AWithOptionalProp'. |
| 7 | +tests/cases/compiler/inKeywordTypeguard.ts(42,11): error TS2339: Property 'b' does not exist on type 'AWithMethod'. |
| 8 | +tests/cases/compiler/inKeywordTypeguard.ts(49,11): error TS2339: Property 'a' does not exist on type 'never'. |
| 9 | +tests/cases/compiler/inKeywordTypeguard.ts(50,11): error TS2339: Property 'b' does not exist on type 'never'. |
| 10 | +tests/cases/compiler/inKeywordTypeguard.ts(52,11): error TS2339: Property 'a' does not exist on type 'AWithMethod | BWithMethod'. |
| 11 | + Property 'a' does not exist on type 'BWithMethod'. |
| 12 | +tests/cases/compiler/inKeywordTypeguard.ts(53,11): error TS2339: Property 'b' does not exist on type 'AWithMethod | BWithMethod'. |
| 13 | + Property 'b' does not exist on type 'AWithMethod'. |
| 14 | +tests/cases/compiler/inKeywordTypeguard.ts(62,11): error TS2339: Property 'b' does not exist on type 'A | C | D'. |
| 15 | + Property 'b' does not exist on type 'A'. |
| 16 | +tests/cases/compiler/inKeywordTypeguard.ts(64,11): error TS2339: Property 'a' does not exist on type 'B'. |
| 17 | +tests/cases/compiler/inKeywordTypeguard.ts(72,32): error TS2339: Property 'b' does not exist on type 'A'. |
| 18 | +tests/cases/compiler/inKeywordTypeguard.ts(74,32): error TS2339: Property 'a' does not exist on type 'B'. |
| 19 | +tests/cases/compiler/inKeywordTypeguard.ts(82,39): error TS2339: Property 'b' does not exist on type 'A'. |
| 20 | +tests/cases/compiler/inKeywordTypeguard.ts(84,39): error TS2339: Property 'a' does not exist on type 'B'. |
| 21 | +tests/cases/compiler/inKeywordTypeguard.ts(94,26): error TS2339: Property 'a' does not exist on type 'never'. |
| 22 | + |
| 23 | + |
| 24 | +==== tests/cases/compiler/inKeywordTypeguard.ts (17 errors) ==== |
| 25 | + class A { a: string; } |
| 26 | + class B { b: string; } |
| 27 | + |
| 28 | + function negativeClassesTest(x: A | B) { |
| 29 | + if ("a" in x) { |
| 30 | + x.b = "1"; |
| 31 | + ~ |
| 32 | +!!! error TS2339: Property 'b' does not exist on type 'A'. |
| 33 | + } else { |
| 34 | + x.a = "1"; |
| 35 | + ~ |
| 36 | +!!! error TS2339: Property 'a' does not exist on type 'B'. |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + function positiveClassesTest(x: A | B) { |
| 41 | + if ("a" in x) { |
| 42 | + x.b = "1"; |
| 43 | + ~ |
| 44 | +!!! error TS2339: Property 'b' does not exist on type 'A'. |
| 45 | + } else { |
| 46 | + x.a = "1"; |
| 47 | + ~ |
| 48 | +!!! error TS2339: Property 'a' does not exist on type 'B'. |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + class AWithOptionalProp { a?: string; } |
| 53 | + class BWithOptionalProp { b?: string; } |
| 54 | + |
| 55 | + function positiveTestClassesWithOptionalProperties(x: AWithOptionalProp | BWithOptionalProp) { |
| 56 | + if ("a" in x) { |
| 57 | + x.a = "1"; |
| 58 | + } else { |
| 59 | + x.b = "1"; |
| 60 | + ~ |
| 61 | +!!! error TS2339: Property 'b' does not exist on type 'AWithOptionalProp | BWithOptionalProp'. |
| 62 | +!!! error TS2339: Property 'b' does not exist on type 'AWithOptionalProp'. |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + class AWithMethod { |
| 67 | + a(): string { return ""; } |
| 68 | + } |
| 69 | + |
| 70 | + class BWithMethod { |
| 71 | + b(): string { return ""; } |
| 72 | + } |
| 73 | + |
| 74 | + function negativeTestClassesWithMembers(x: AWithMethod | BWithMethod) { |
| 75 | + if ("a" in x) { |
| 76 | + x.a(); |
| 77 | + x.b(); |
| 78 | + ~ |
| 79 | +!!! error TS2339: Property 'b' does not exist on type 'AWithMethod'. |
| 80 | + } else { |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + function negativeTestClassesWithMemberMissingInBothClasses(x: AWithMethod | BWithMethod) { |
| 85 | + if ("c" in x) { |
| 86 | + x.a(); |
| 87 | + ~ |
| 88 | +!!! error TS2339: Property 'a' does not exist on type 'never'. |
| 89 | + x.b(); |
| 90 | + ~ |
| 91 | +!!! error TS2339: Property 'b' does not exist on type 'never'. |
| 92 | + } else { |
| 93 | + x.a(); |
| 94 | + ~ |
| 95 | +!!! error TS2339: Property 'a' does not exist on type 'AWithMethod | BWithMethod'. |
| 96 | +!!! error TS2339: Property 'a' does not exist on type 'BWithMethod'. |
| 97 | + x.b(); |
| 98 | + ~ |
| 99 | +!!! error TS2339: Property 'b' does not exist on type 'AWithMethod | BWithMethod'. |
| 100 | +!!! error TS2339: Property 'b' does not exist on type 'AWithMethod'. |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + class C { a: string; } |
| 105 | + class D { a: string; } |
| 106 | + |
| 107 | + function negativeMultipleClassesTest(x: A | B | C | D) { |
| 108 | + if ("a" in x) { |
| 109 | + x.b = "1"; |
| 110 | + ~ |
| 111 | +!!! error TS2339: Property 'b' does not exist on type 'A | C | D'. |
| 112 | +!!! error TS2339: Property 'b' does not exist on type 'A'. |
| 113 | + } else { |
| 114 | + x.a = "1"; |
| 115 | + ~ |
| 116 | +!!! error TS2339: Property 'a' does not exist on type 'B'. |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + class ClassWithUnionProp { prop: A | B } |
| 121 | + |
| 122 | + function negativePropTest(x: ClassWithUnionProp) { |
| 123 | + if ("a" in x.prop) { |
| 124 | + let y: string = x.prop.b; |
| 125 | + ~ |
| 126 | +!!! error TS2339: Property 'b' does not exist on type 'A'. |
| 127 | + } else { |
| 128 | + let z: string = x.prop.a; |
| 129 | + ~ |
| 130 | +!!! error TS2339: Property 'a' does not exist on type 'B'. |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + class NegativeClassTest { |
| 135 | + protected prop: A | B; |
| 136 | + inThis() { |
| 137 | + if ("a" in this.prop) { |
| 138 | + let z: number = this.prop.b; |
| 139 | + ~ |
| 140 | +!!! error TS2339: Property 'b' does not exist on type 'A'. |
| 141 | + } else { |
| 142 | + let y: string = this.prop.a; |
| 143 | + ~ |
| 144 | +!!! error TS2339: Property 'a' does not exist on type 'B'. |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + class UnreachableCodeDetection { |
| 150 | + a: string; |
| 151 | + inThis() { |
| 152 | + if ("a" in this) { |
| 153 | + } else { |
| 154 | + let y = this.a; |
| 155 | + ~ |
| 156 | +!!! error TS2339: Property 'a' does not exist on type 'never'. |
| 157 | + } |
| 158 | + } |
| 159 | + } |
0 commit comments