From e0a286a01dcf9bcc109d1e35ec2be7c87253690a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 23 Jan 2020 10:07:43 -0800 Subject: [PATCH] =?UTF-8?q?[Cherry-pick]=20Allow=20ambient=20accessors=20t?= =?UTF-8?q?o=20omit=20their=20types=20unde=E2=80=A6=20(#36280)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix noImplicitAny check on ambient private getters (#33896) * Fix scripts. Co-authored-by: Klaus Meinhardt --- scripts/build/utils.js | 2 +- scripts/tslint/formatters/autolinkableStylishFormatter.ts | 2 +- src/compiler/checker.ts | 6 ++++-- ...noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.js | 2 ++ ...licitAnyAndPrivateMembersWithoutTypeAnnotations.symbols | 7 +++++++ ...mplicitAnyAndPrivateMembersWithoutTypeAnnotations.types | 7 +++++++ ...noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.ts | 2 ++ 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/build/utils.js b/scripts/build/utils.js index a67742cca68f2..6664a2fa67aec 100644 --- a/scripts/build/utils.js +++ b/scripts/build/utils.js @@ -8,7 +8,7 @@ const mkdirp = require("mkdirp"); const del = require("del"); const File = require("vinyl"); const ts = require("../../lib/typescript"); -const { default: chalk } = require("chalk"); +const chalk = require("chalk"); const { spawn } = require("child_process"); const { CancellationToken, CancelError, Deferred } = require("prex"); const { Readable, Duplex } = require("stream"); diff --git a/scripts/tslint/formatters/autolinkableStylishFormatter.ts b/scripts/tslint/formatters/autolinkableStylishFormatter.ts index 23e01bc8587e1..6586a777b4fcd 100644 --- a/scripts/tslint/formatters/autolinkableStylishFormatter.ts +++ b/scripts/tslint/formatters/autolinkableStylishFormatter.ts @@ -1,5 +1,5 @@ import * as Lint from "tslint"; -import chalk from "chalk"; +import chalk = require("chalk"); import { sep } from "path"; function groupBy(array: ReadonlyArray | undefined, getGroupId: (elem: T, index: number) => number | string): T[][] { if (!array) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e97b27bdc2c7..f273188690197 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5943,8 +5943,10 @@ namespace ts { } } else { - Debug.assert(!!getter, "there must existed 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)); + Debug.assert(!!getter, "there must exist a getter as we are current checking either setter or getter in this function"); + if (!isPrivateWithinAmbient(getter!)) { + errorOrSuggestion(noImplicitAny, getter!, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol)); + } } type = 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