Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20555,7 +20555,7 @@ namespace ts {
}

function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) {
if (type.flags & (TypeFlags.Union | TypeFlags.Object | TypeFlags.Intersection) || isThisTypeParameter(type)) {
const propName = escapeLeadingUnderscores(literal.text);
return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue));
}
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/inKeywordTypeguard.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ tests/cases/compiler/inKeywordTypeguard.ts(74,32): error TS2339: Property 'a' do
tests/cases/compiler/inKeywordTypeguard.ts(82,39): error TS2339: Property 'b' does not exist on type 'A'.
tests/cases/compiler/inKeywordTypeguard.ts(84,39): error TS2339: Property 'a' does not exist on type 'B'.
tests/cases/compiler/inKeywordTypeguard.ts(94,26): error TS2339: Property 'a' does not exist on type 'never'.
tests/cases/compiler/inKeywordTypeguard.ts(103,13): error TS2322: Type '{ a: string; } & { b: string; }' is not assignable to type 'never'.


==== tests/cases/compiler/inKeywordTypeguard.ts (18 errors) ====
==== tests/cases/compiler/inKeywordTypeguard.ts (17 errors) ====
class A { a: string; }
class B { b: string; }

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

2 changes: 1 addition & 1 deletion tests/baselines/reference/inKeywordTypeguard.types
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function positiveIntersectionTest(x: { a: string } & { b: string }) {
} else {
let n: never = x;
>n : never
>x : { a: string; } & { b: string; }
>x : never
}
}