Skip to content

Stop binding type predicate types twice #22210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2018
Merged
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
13 changes: 1 addition & 12 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ namespace ts {
seenThisKeyword = true;
return;
case SyntaxKind.TypePredicate:
return checkTypePredicate(node as TypePredicateNode);
break; // Binding the children will handle everything
case SyntaxKind.TypeParameter:
return bindTypeParameter(node as TypeParameterDeclaration);
case SyntaxKind.Parameter:
Expand Down Expand Up @@ -2204,17 +2204,6 @@ namespace ts {
return bindAnonymousDeclaration(<Declaration>node, SymbolFlags.TypeLiteral, InternalSymbolName.Type);
}

function checkTypePredicate(node: TypePredicateNode) {
const { parameterName, type } = node;
if (parameterName && parameterName.kind === SyntaxKind.Identifier) {
checkStrictModeIdentifier(parameterName);
}
if (parameterName && parameterName.kind === SyntaxKind.ThisType) {
seenThisKeyword = true;
}
bind(type);
}

function bindSourceFileIfExternalModule() {
setExportContextFlag(file);
if (isExternalModule(file)) {
Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/typeGuardOnContainerTypeNoHang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [typeGuardOnContainerTypeNoHang.ts]
export namespace TypeGuards {
export function IsObject(value: any) : value is {[index:string]:any} {
return typeof(value) === 'object'
}

}

//// [typeGuardOnContainerTypeNoHang.js]
"use strict";
exports.__esModule = true;
var TypeGuards;
(function (TypeGuards) {
function IsObject(value) {
return typeof (value) === 'object';
}
TypeGuards.IsObject = IsObject;
})(TypeGuards = exports.TypeGuards || (exports.TypeGuards = {}));
15 changes: 15 additions & 0 deletions tests/baselines/reference/typeGuardOnContainerTypeNoHang.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=== tests/cases/compiler/typeGuardOnContainerTypeNoHang.ts ===
export namespace TypeGuards {
>TypeGuards : Symbol(TypeGuards, Decl(typeGuardOnContainerTypeNoHang.ts, 0, 0))

export function IsObject(value: any) : value is {[index:string]:any} {
>IsObject : Symbol(IsObject, Decl(typeGuardOnContainerTypeNoHang.ts, 0, 29))
>value : Symbol(value, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 29))
>value : Symbol(value, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 29))
>index : Symbol(index, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 54))

return typeof(value) === 'object'
>value : Symbol(value, Decl(typeGuardOnContainerTypeNoHang.ts, 1, 29))
}

}
19 changes: 19 additions & 0 deletions tests/baselines/reference/typeGuardOnContainerTypeNoHang.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== tests/cases/compiler/typeGuardOnContainerTypeNoHang.ts ===
export namespace TypeGuards {
>TypeGuards : typeof TypeGuards

export function IsObject(value: any) : value is {[index:string]:any} {
>IsObject : (value: any) => value is { [index: string]: any; }
>value : any
>value : any
>index : string

return typeof(value) === 'object'
>typeof(value) === 'object' : boolean
>typeof(value) : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
>(value) : any
>value : any
>'object' : "object"
}

}
6 changes: 6 additions & 0 deletions tests/cases/compiler/typeGuardOnContainerTypeNoHang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export namespace TypeGuards {
export function IsObject(value: any) : value is {[index:string]:any} {
return typeof(value) === 'object'
}

}