Skip to content

Commit 255b65a

Browse files
Revert "Revert #37106 (#38172)"
This reverts commit 84c83da.
1 parent 6a6c83c commit 255b65a

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20555,7 +20555,7 @@ namespace ts {
2055520555
}
2055620556

2055720557
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
20558-
if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) {
20558+
if (type.flags & (TypeFlags.Union | TypeFlags.Object | TypeFlags.Intersection) || isThisTypeParameter(type)) {
2055920559
const propName = escapeLeadingUnderscores(literal.text);
2056020560
return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue));
2056120561
}

tests/baselines/reference/inKeywordTypeguard.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ tests/cases/compiler/inKeywordTypeguard.ts(74,32): error TS2339: Property 'a' do
1919
tests/cases/compiler/inKeywordTypeguard.ts(82,39): error TS2339: Property 'b' does not exist on type 'A'.
2020
tests/cases/compiler/inKeywordTypeguard.ts(84,39): error TS2339: Property 'a' does not exist on type 'B'.
2121
tests/cases/compiler/inKeywordTypeguard.ts(94,26): error TS2339: Property 'a' does not exist on type 'never'.
22-
tests/cases/compiler/inKeywordTypeguard.ts(103,13): error TS2322: Type '{ a: string; } & { b: string; }' is not assignable to type 'never'.
2322

2423

25-
==== tests/cases/compiler/inKeywordTypeguard.ts (18 errors) ====
24+
==== tests/cases/compiler/inKeywordTypeguard.ts (17 errors) ====
2625
class A { a: string; }
2726
class B { b: string; }
2827

@@ -164,8 +163,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(103,13): error TS2322: Type '{ a: str
164163
let s: string = x.a;
165164
} else {
166165
let n: never = x;
167-
~
168-
!!! error TS2322: Type '{ a: string; } & { b: string; }' is not assignable to type 'never'.
169166
}
170167
}
171168

tests/baselines/reference/inKeywordTypeguard.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function positiveIntersectionTest(x: { a: string } & { b: string }) {
318318
} else {
319319
let n: never = x;
320320
>n : never
321-
>x : { a: string; } & { b: string; }
321+
>x : never
322322
}
323323
}
324324

0 commit comments

Comments
 (0)