Skip to content

Commit 7a31192

Browse files
authored
Stop binding type predicate types twice (microsoft#22210)
1 parent fabd325 commit 7a31192

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ namespace ts {
20712071
seenThisKeyword = true;
20722072
return;
20732073
case SyntaxKind.TypePredicate:
2074-
return checkTypePredicate(node as TypePredicateNode);
2074+
break; // Binding the children will handle everything
20752075
case SyntaxKind.TypeParameter:
20762076
return bindTypeParameter(node as TypeParameterDeclaration);
20772077
case SyntaxKind.Parameter:
@@ -2204,17 +2204,6 @@ namespace ts {
22042204
return bindAnonymousDeclaration(<Declaration>node, SymbolFlags.TypeLiteral, InternalSymbolName.Type);
22052205
}
22062206

2207-
function checkTypePredicate(node: TypePredicateNode) {
2208-
const { parameterName, type } = node;
2209-
if (parameterName && parameterName.kind === SyntaxKind.Identifier) {
2210-
checkStrictModeIdentifier(parameterName);
2211-
}
2212-
if (parameterName && parameterName.kind === SyntaxKind.ThisType) {
2213-
seenThisKeyword = true;
2214-
}
2215-
bind(type);
2216-
}
2217-
22182207
function bindSourceFileIfExternalModule() {
22192208
setExportContextFlag(file);
22202209
if (isExternalModule(file)) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [typeGuardOnContainerTypeNoHang.ts]
2+
export namespace TypeGuards {
3+
export function IsObject(value: any) : value is {[index:string]:any} {
4+
return typeof(value) === 'object'
5+
}
6+
7+
}
8+
9+
//// [typeGuardOnContainerTypeNoHang.js]
10+
"use strict";
11+
exports.__esModule = true;
12+
var TypeGuards;
13+
(function (TypeGuards) {
14+
function IsObject(value) {
15+
return typeof (value) === 'object';
16+
}
17+
TypeGuards.IsObject = IsObject;
18+
})(TypeGuards = exports.TypeGuards || (exports.TypeGuards = {}));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/typeGuardOnContainerTypeNoHang.ts ===
2+
export namespace TypeGuards {
3+
>TypeGuards : Symbol(TypeGuards, Decl(typeGuardOnContainerTypeNoHang.ts, 0, 0))
4+
5+
export function IsObject(value: any) : value is {[index:string]:any} {
6+
>IsObject : Symbol(IsObject, Decl(typeGuardOnContainerTypeNoHang.ts, 0, 29))
7+
>value : Symbol(value, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 29))
8+
>value : Symbol(value, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 29))
9+
>index : Symbol(index, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 54))
10+
11+
return typeof(value) === 'object'
12+
>value : Symbol(value, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 29))
13+
}
14+
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/typeGuardOnContainerTypeNoHang.ts ===
2+
export namespace TypeGuards {
3+
>TypeGuards : typeof TypeGuards
4+
5+
export function IsObject(value: any) : value is {[index:string]:any} {
6+
>IsObject : (value: any) => value is { [index: string]: any; }
7+
>value : any
8+
>value : any
9+
>index : string
10+
11+
return typeof(value) === 'object'
12+
>typeof(value) === 'object' : boolean
13+
>typeof(value) : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
14+
>(value) : any
15+
>value : any
16+
>'object' : "object"
17+
}
18+
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export namespace TypeGuards {
2+
export function IsObject(value: any) : value is {[index:string]:any} {
3+
return typeof(value) === 'object'
4+
}
5+
6+
}

0 commit comments

Comments
 (0)