From f220876278db60343a48129bc39bd9267963b2e5 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 9 Oct 2019 19:05:26 +0200 Subject: [PATCH 1/2] Fix noImplicitAny check on ambient private getters (#33896) --- src/compiler/checker.ts | 6 ++++-- ...noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.js | 2 ++ ...licitAnyAndPrivateMembersWithoutTypeAnnotations.symbols | 7 +++++++ ...mplicitAnyAndPrivateMembersWithoutTypeAnnotations.types | 7 +++++++ ...noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.ts | 2 ++ 5 files changed, 22 insertions(+), 2 deletions(-) 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 From e3e08f337b9e80facd9427462520b6069e265958 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sat, 18 Jan 2020 13:42:38 -0800 Subject: [PATCH 2/2] Fix scripts. --- scripts/build/utils.js | 2 +- scripts/tslint/formatters/autolinkableStylishFormatter.ts | 2 +- 2 files changed, 2 insertions(+), 2 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) {