diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 57f3d737927..c8150d644a2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3603,7 +3603,8 @@ module ts { function getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments): Type { let links = getNodeLinks(node); if (!links.resolvedType) { - // We only support expressions that are simple qualified names. For other expressions this produces undefined. let typeNameOrExpression = node.kind === SyntaxKind.TypeReference ? (node).typeName : + // We only support expressions that are simple qualified names. For other expressions this produces undefined. + let typeNameOrExpression = node.kind === SyntaxKind.TypeReference ? (node).typeName : isSupportedExpressionWithTypeArguments(node) ? (node).expression : undefined; let symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol; @@ -5255,14 +5256,14 @@ module ts { if (source.typePredicate && target.typePredicate) { if (target.typePredicate.parameterIndex === source.typePredicate.parameterIndex) { // Return types from type predicates are treated as booleans. In order to infer types - // from type predicates we would need to infer from the type of type predicates. Since - // we can't infer any type information from the return types — we can just add a return - // statement after the below infer type statement. + // from type predicates we would need to infer using the type within the type predicate + // (i.e. 'Foo' from 'x is Foo'). inferFromTypes(source.typePredicate.type, target.typePredicate.type); } - return; } - inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + else { + inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } } function inferFromIndexTypes(source: Type, target: Type, sourceKind: IndexKind, targetKind: IndexKind) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2f29ce0b405..df40d10ddf1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1903,23 +1903,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function emitNewExpression(node: NewExpression) { write("new "); - // Spread operator logic can be supported in new expressions in ES5 using a combination + // Spread operator logic is supported in new expressions in ES5 using a combination // of Function.prototype.bind() and Function.prototype.apply(). // // Example: // - // var arguments = [1, 2, 3, 4, 5]; - // new Array(...arguments); + // var args = [1, 2, 3, 4, 5]; + // new Array(...args); // - // Could be transpiled into ES5: + // is compiled into the following ES5: // - // var arguments = [1, 2, 3, 4, 5]; - // new (Array.bind.apply(Array, [void 0].concat(arguments))); + // var args = [1, 2, 3, 4, 5]; + // new (Array.bind.apply(Array, [void 0].concat(args))); // - // `[void 0]` is the first argument which represents `thisArg` to the bind method above. - // And `thisArg` will be set to the return value of the constructor when instantiated - // with the new operator — regardless of any value we set `thisArg` to. Thus, we set it - // to an undefined, `void 0`. + // The 'thisArg' to 'bind' is ignored when invoking the result of 'bind' with 'new', + // Thus, we set it to undefined ('void 0'). if (languageVersion === ScriptTarget.ES5 && node.arguments && hasSpreadElement(node.arguments)) {