Skip to content

Commit

Permalink
Revert #37106 (#38172)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCavanaugh authored Apr 24, 2020
1 parent b1d464d commit 84c83da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
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 | TypeFlags.Intersection) || isThisTypeParameter(type)) {
if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) {
const propName = escapeLeadingUnderscores(literal.text);
return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue));
}
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/inKeywordTypeguard.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ 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 (17 errors) ====
==== tests/cases/compiler/inKeywordTypeguard.ts (18 errors) ====
class A { a: string; }
class B { b: string; }

Expand Down Expand Up @@ -163,6 +164,8 @@ tests/cases/compiler/inKeywordTypeguard.ts(94,26): error TS2339: Property 'a' do
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 : never
>x : { a: string; } & { b: string; }
}
}

0 comments on commit 84c83da

Please sign in to comment.