diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2c68ea66ba..f5261b62ae 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2248,10 +2248,12 @@ namespace ts { property.questionToken = questionToken; property.type = parseTypeAnnotation(); - // Although object type properties cannot not have initializers, we attempt to parse an initializer - // so we can report in the checker that an interface property or object type literal property cannot - // have an initializer. - property.initializer = parseNonParameterInitializer(); + if (token === SyntaxKind.EqualsToken) { + // Although object type properties cannot not have initializers, we attempt + // to parse an initializer so we can report in the checker that an interface + // property or object type literal property cannot have an initializer. + property.initializer = parseNonParameterInitializer(); + } parseTypeMemberSemicolon(); return finishNode(property); diff --git a/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt b/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt index e4f923def5..00442f4f87 100644 --- a/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt +++ b/tests/baselines/reference/objectTypeLiteralSyntax2.errors.txt @@ -1,9 +1,7 @@ -tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,22): error TS1005: '=' expected. -tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,22): error TS2304: Cannot find name 'bar'. -tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,25): error TS1005: ';' expected. +tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,22): error TS1005: ';' expected. -==== tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts (3 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts (1 errors) ==== var x: { foo: string, bar: string @@ -17,8 +15,4 @@ tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,2 var z: { foo: string bar: string } ~~~ -!!! error TS1005: '=' expected. - ~~~ -!!! error TS2304: Cannot find name 'bar'. - ~ !!! error TS1005: ';' expected. \ No newline at end of file