Skip to content

Use of private fields with noImplicitAny triggers TS7008  #36630

Closed
@RomainMuller

Description

@RomainMuller

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions