diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5bd2e1f8ec8..36be5f8001e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1665,6 +1665,13 @@ module ts { } return type; } + + // If it is a short-hand property assignment; Use the type of the identifier + if (declaration.kind === SyntaxKind.ShortHandPropertyAssignment) { + var type = checkIdentifier((declaration.name)); + return type + } + // Rest parameters default to type any[], other parameters default to type any var type = declaration.flags & NodeFlags.Rest ? createArrayType(anyType) : anyType; checkImplicitAny(type); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 75ff2993609..2657fc83668 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -574,6 +574,7 @@ module ts { case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: case SyntaxKind.PropertyAssignment: + case SyntaxKind.ShortHandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: case SyntaxKind.FunctionDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index d6465084fa4..916c468ea3d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1969,7 +1969,7 @@ module ts { /** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */ function isNameOfPropertyAssignment(node: Node): boolean { return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) && - node.parent.kind === SyntaxKind.PropertyAssignment && (node.parent).name === node; + (node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShortHandPropertyAssignment) && (node.parent).name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean { @@ -2648,7 +2648,7 @@ module ts { var existingMemberNames: Map = {}; forEach(existingMembers, m => { - if (m.kind !== SyntaxKind.PropertyAssignment) { + if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShortHandPropertyAssignment) { // Ignore omitted expressions for missing members in the object literal return; } @@ -4569,6 +4569,7 @@ module ts { case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: case SyntaxKind.PropertyAssignment: + case SyntaxKind.ShortHandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: case SyntaxKind.Constructor: