Address PR comments

This commit is contained in:
Nathan Shively-Sanders
2016-03-30 15:01:16 -07:00
parent 0113ad5250
commit e4ed7f904e
7 changed files with 76 additions and 40 deletions

View File

@@ -5379,11 +5379,8 @@ namespace ts {
function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration) {
const areAllParametersUntyped = !forEach(node.parameters, p => p.type);
if (node.kind === SyntaxKind.ArrowFunction) {
return !node.typeParameters && node.parameters.length && areAllParametersUntyped;
}
const hasThisType = node.parameters.length && (<Identifier>node.parameters[0].name).text === "this" && node.parameters[0].type;
return !node.typeParameters && areAllParametersUntyped && !hasThisType;
const isNullaryArrow = node.kind === SyntaxKind.ArrowFunction && !node.parameters.length;
return !node.typeParameters && areAllParametersUntyped && !isNullaryArrow;
}
function getTypeWithoutSignatures(type: Type): Type {
@@ -8072,20 +8069,20 @@ namespace ts {
if (signature.thisType) {
return signature.thisType;
}
if (container.parent && container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
// Note: this works because object literal methods are deferred,
// which means that the type of the containing object literal is already known.
const type = checkExpressionCached(<ObjectLiteralExpression>container.parent);
if (type) {
return type;
}
}
}
if (isClassLike(container.parent)) {
const symbol = getSymbolOfNode(container.parent);
const type = container.flags & NodeFlags.Static ? getTypeOfSymbol(symbol) : (<InterfaceType>getDeclaredTypeOfSymbol(symbol)).thisType;
return getNarrowedTypeOfReference(type, node);
}
if (container.parent && container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
// Note: this works because object literal methods are deferred,
// which means that the type of the containing object literal is already known.
const type = checkExpressionCached(<ObjectLiteralExpression>container.parent);
if (type) {
return type;
}
}
if (isInJavaScriptFile(node)) {
const type = getTypeForThisExpressionFromJSDoc(container);
@@ -12401,9 +12398,12 @@ namespace ts {
if (indexOf(func.parameters, node) !== 0) {
error(node, Diagnostics.this_parameter_must_be_the_first_parameter);
}
if (func.kind === SyntaxKind.Constructor) {
if (func.kind === SyntaxKind.Constructor || func.kind === SyntaxKind.ConstructSignature) {
error(node, Diagnostics.A_constructor_cannot_have_a_this_parameter);
}
if (func.kind === SyntaxKind.SetAccessor) {
error(node, Diagnostics.A_setter_cannot_have_a_this_parameter);
}
}
// Only check rest parameter type if it's not a binding pattern. Since binding patterns are

View File

@@ -125,6 +125,7 @@ namespace ts {
{
name: "noImplicitThis",
type: "boolean",
description: Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type,
},
{
name: "noLib",

View File

@@ -1887,10 +1887,14 @@
"category": "Error",
"code": 2680
},
"'this' implicitly has type 'any' because it does not have a type annotation.": {
"A setter cannot have a 'this' parameter.": {
"category": "Error",
"code": 2681
},
"'this' implicitly has type 'any' because it does not have a type annotation.": {
"category": "Error",
"code": 2682
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
@@ -2636,6 +2640,10 @@
"category": "Message",
"code": 6113
},
"Raise error on 'this' expressions with an implied 'any' type.": {
"category": "Message",
"code": 6114
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",