diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e8a535b844fec..12d393b709e9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7436,7 +7436,9 @@ namespace ts { } else { Debug.assert(!!getter, "there must exist a getter as we are current checking either setter or getter in this function"); - errorOrSuggestion(noImplicitAny, getter!, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol)); + if (!isPrivateWithinAmbient(getter!)) { + errorOrSuggestion(noImplicitAny, getter!, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol)); + } } return anyType; } diff --git a/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.js b/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.js index 5392b163477b2..633a1d07876b4 100644 --- a/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.js +++ b/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.js @@ -5,6 +5,8 @@ declare class Something { private static someStaticVar; private someVar; + private get getter(); + private set setter(v); } //// [app.ts] diff --git a/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.symbols b/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.symbols index 0cfd1cbff07a5..9908d70ba5e6f 100644 --- a/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.symbols +++ b/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.symbols @@ -13,5 +13,12 @@ declare class Something private someVar; >someVar : Symbol(Something.someVar, Decl(test.d.ts, 2, 33)) + + private get getter(); +>getter : Symbol(Something.getter, Decl(test.d.ts, 3, 20)) + + private set setter(v); +>setter : Symbol(Something.setter, Decl(test.d.ts, 4, 25)) +>v : Symbol(v, Decl(test.d.ts, 5, 23)) } diff --git a/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.types b/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.types index 071d8a1aa881b..5f69adcf6318b 100644 --- a/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.types +++ b/tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.types @@ -14,5 +14,12 @@ declare class Something private someVar; >someVar : any + + private get getter(); +>getter : any + + private set setter(v); +>setter : any +>v : any } diff --git a/tests/cases/compiler/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.ts b/tests/cases/compiler/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.ts index dd3513f9b3a32..0c6c1566df35f 100644 --- a/tests/cases/compiler/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.ts +++ b/tests/cases/compiler/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.ts @@ -3,6 +3,8 @@ declare class Something { private static someStaticVar; private someVar; + private get getter(); + private set setter(v); } // @noimplicitany: true