Skip to content

Exempt ambient private properties from noImplicitAny #36640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28944,7 +28944,7 @@ namespace ts {
}

function isPrivateWithinAmbient(node: Node): boolean {
return hasModifier(node, ModifierFlags.Private) && !!(node.flags & NodeFlags.Ambient);
return (hasModifier(node, ModifierFlags.Private) || isPrivateIdentifierPropertyDeclaration(node)) && !!(node.flags & NodeFlags.Ambient);
}

function getEffectiveDeclarationFlags(n: Declaration, flagsToCheck: ModifierFlags): ModifierFlags {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests/cases/conformance/classes/members/privateNames/privateNameAmbientNoImplicitAny.ts(5,5): error TS7008: Member '#prop' implicitly has an 'any' type.


==== tests/cases/conformance/classes/members/privateNames/privateNameAmbientNoImplicitAny.ts (1 errors) ====
declare class A {
#prop;
}
class B {
#prop;
~~~~~
!!! error TS7008: Member '#prop' implicitly has an 'any' type.
}
12 changes: 12 additions & 0 deletions tests/baselines/reference/privateNameAmbientNoImplicitAny.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [privateNameAmbientNoImplicitAny.ts]
declare class A {
#prop;
}
class B {
#prop;
}

//// [privateNameAmbientNoImplicitAny.js]
class B {
#prop;
}
13 changes: 13 additions & 0 deletions tests/baselines/reference/privateNameAmbientNoImplicitAny.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/classes/members/privateNames/privateNameAmbientNoImplicitAny.ts ===
declare class A {
>A : Symbol(A, Decl(privateNameAmbientNoImplicitAny.ts, 0, 0))

#prop;
>#prop : Symbol(A.#prop, Decl(privateNameAmbientNoImplicitAny.ts, 0, 17))
}
class B {
>B : Symbol(B, Decl(privateNameAmbientNoImplicitAny.ts, 2, 1))

#prop;
>#prop : Symbol(B.#prop, Decl(privateNameAmbientNoImplicitAny.ts, 3, 9))
}
13 changes: 13 additions & 0 deletions tests/baselines/reference/privateNameAmbientNoImplicitAny.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/classes/members/privateNames/privateNameAmbientNoImplicitAny.ts ===
declare class A {
>A : A

#prop;
>#prop : any
}
class B {
>B : B

#prop;
>#prop : any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @noImplicitAny: true
// @target: ESNext
declare class A {
#prop;
}
class B {
#prop;
}