Skip to content

Commit e0a286a

Browse files
[Cherry-pick] Allow ambient accessors to omit their types unde… (#36280)
* Fix noImplicitAny check on ambient private getters (#33896) * Fix scripts. Co-authored-by: Klaus Meinhardt <[email protected]>
1 parent 0dbaef5 commit e0a286a

7 files changed

+24
-4
lines changed

scripts/build/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const mkdirp = require("mkdirp");
88
const del = require("del");
99
const File = require("vinyl");
1010
const ts = require("../../lib/typescript");
11-
const { default: chalk } = require("chalk");
11+
const chalk = require("chalk");
1212
const { spawn } = require("child_process");
1313
const { CancellationToken, CancelError, Deferred } = require("prex");
1414
const { Readable, Duplex } = require("stream");

scripts/tslint/formatters/autolinkableStylishFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Lint from "tslint";
2-
import chalk from "chalk";
2+
import chalk = require("chalk");
33
import { sep } from "path";
44
function groupBy<T>(array: ReadonlyArray<T> | undefined, getGroupId: (elem: T, index: number) => number | string): T[][] {
55
if (!array) {

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5943,8 +5943,10 @@ namespace ts {
59435943
}
59445944
}
59455945
else {
5946-
Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function");
5947-
errorOrSuggestion(noImplicitAny, getter!, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol));
5946+
Debug.assert(!!getter, "there must exist a getter as we are current checking either setter or getter in this function");
5947+
if (!isPrivateWithinAmbient(getter!)) {
5948+
errorOrSuggestion(noImplicitAny, getter!, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol));
5949+
}
59485950
}
59495951
type = anyType;
59505952
}

tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ declare class Something
55
{
66
private static someStaticVar;
77
private someVar;
8+
private get getter();
9+
private set setter(v);
810
}
911

1012
//// [app.ts]

tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.symbols

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,12 @@ declare class Something
1313

1414
private someVar;
1515
>someVar : Symbol(Something.someVar, Decl(test.d.ts, 2, 33))
16+
17+
private get getter();
18+
>getter : Symbol(Something.getter, Decl(test.d.ts, 3, 20))
19+
20+
private set setter(v);
21+
>setter : Symbol(Something.setter, Decl(test.d.ts, 4, 25))
22+
>v : Symbol(v, Decl(test.d.ts, 5, 23))
1623
}
1724

tests/baselines/reference/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ declare class Something
1414

1515
private someVar;
1616
>someVar : any
17+
18+
private get getter();
19+
>getter : any
20+
21+
private set setter(v);
22+
>setter : any
23+
>v : any
1724
}
1825

tests/cases/compiler/noImplicitAnyAndPrivateMembersWithoutTypeAnnotations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ declare class Something
33
{
44
private static someStaticVar;
55
private someVar;
6+
private get getter();
7+
private set setter(v);
68
}
79

810
// @noimplicitany: true

0 commit comments

Comments
 (0)