We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 23b500c commit a46e9aeCopy full SHA for a46e9ae
src/compiler/checker.ts
@@ -20241,7 +20241,7 @@ namespace ts {
20241
}
20242
20243
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
20244
- if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) {
+ if (type.flags & (TypeFlags.Union | TypeFlags.Object | TypeFlags.Intersection) || isThisTypeParameter(type)) {
20245
const propName = escapeLeadingUnderscores(literal.text);
20246
return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue));
20247
tests/baselines/reference/inKeywordTypeguard.errors.txt
@@ -156,4 +156,13 @@ tests/cases/compiler/inKeywordTypeguard.ts(94,26): error TS2339: Property 'a' do
156
!!! error TS2339: Property 'a' does not exist on type 'never'.
157
158
159
- }
+ }
160
+
161
+ function positiveIntersectionTest(x: { a: string } & { b: string }) {
162
+ if ("a" in x) {
163
+ let s: string = x.a;
164
+ } else {
165
+ let n: never = x;
166
167
168
tests/baselines/reference/inKeywordTypeguard.js
@@ -95,7 +95,16 @@ class UnreachableCodeDetection {
95
let y = this.a;
96
97
98
-}
+}
99
100
+function positiveIntersectionTest(x: { a: string } & { b: string }) {
101
102
103
104
105
106
107
108
109
//// [inKeywordTypeguard.js]
110
var A = /** @class */ (function () {
@@ -228,3 +237,11 @@ var UnreachableCodeDetection = /** @class */ (function () {
228
237
};
229
238
return UnreachableCodeDetection;
230
239
}());
240
+function positiveIntersectionTest(x) {
241
242
+ var s = x.a;
243
244
+ else {
245
+ var n = x;
246
247
tests/baselines/reference/inKeywordTypeguard.symbols
@@ -239,3 +239,26 @@ class UnreachableCodeDetection {
+>positiveIntersectionTest : Symbol(positiveIntersectionTest, Decl(inKeywordTypeguard.ts, 96, 1))
+>x : Symbol(x, Decl(inKeywordTypeguard.ts, 98, 34))
+>a : Symbol(a, Decl(inKeywordTypeguard.ts, 98, 38))
+>b : Symbol(b, Decl(inKeywordTypeguard.ts, 98, 54))
248
249
250
251
252
253
+>s : Symbol(s, Decl(inKeywordTypeguard.ts, 100, 11))
254
+>x.a : Symbol(a, Decl(inKeywordTypeguard.ts, 98, 38))
255
256
257
258
259
260
+>n : Symbol(n, Decl(inKeywordTypeguard.ts, 102, 11))
261
262
263
264
tests/baselines/reference/inKeywordTypeguard.types
@@ -297,3 +297,28 @@ class UnreachableCodeDetection {
297
298
299
300
301
302
+>positiveIntersectionTest : (x: { a: string; } & { b: string; }) => void
303
+>x : { a: string; } & { b: string; }
304
+>a : string
305
+>b : string
306
307
308
+>"a" in x : boolean
309
+>"a" : "a"
310
311
312
313
+>s : string
314
+>x.a : string
315
316
317
318
319
320
+>n : never
321
+>x : never
322
323
324
tests/cases/compiler/inKeywordTypeguard.ts
@@ -94,4 +94,12 @@ class UnreachableCodeDetection {
94
0 commit comments