Skip to content

Use of private fields with noImplicitAny triggers TS7008 #36630

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

Closed
RomainMuller opened this issue Feb 5, 2020 · 1 comment · Fixed by #36640
Closed

Use of private fields with noImplicitAny triggers TS7008 #36630

RomainMuller opened this issue Feb 5, 2020 · 1 comment · Fixed by #36640

Comments

@RomainMuller
Copy link

RomainMuller commented Feb 5, 2020

TypeScript Version: 3.8.0-dev.20200205

Search Terms:

  • "#private" noImplicitAny
  • "#private" TS7008

Code

// tsconfig.json (in "foo" and "bar" modules)
{
  "compilerOptions": {
    "target": "ES2018",
    "noImplicitAny": true,
    "declaration": true
  }
}
// In module "foo", "index.ts"
export class Foo {
  readonly #bar: string = 'baz';

  public get bar() {
    return this.#bar;
  }
}
// in module "bar", "index.ts"
import { Foo } from 'foo';

new Foo();

Expected behavior:
I can declare private fields in classes exported by one package/module, and consume that from another package/module without issues.

Actual behavior:
The module that contains the private fields yields a #private declaration that triggers the noImplicitAny error when it's imported from the other module:

// "index.d.ts" in module "foo"
export declare class Foo {
    #private;
//  ~~~~~~~~ error TSC7008: Member '#private' implicitly has an 'any' type
    get bar(): string;
}

Related Issues: Similar to #6415, except with private-named fields.

@ajafff
Copy link
Contributor

ajafff commented Feb 5, 2020

Simplified code which reproduces in the playground: http://www.typescriptlang.org/play/?ts=3.8.0-dev.20200204&ssl=1&ssc=1&pln=3&pc=2#code/CYUwxgNghgTiAEkoGdnwMLwN4Ch7-gGIAHGAe2IG4cBfIA

declare class C {
    #prop;
}

PR incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants