Skip to content

Constructor must be set public, protected, or private #3173

@tdkehoe

Description

@tdkehoe

Version info

Angular: 13.2.5

Firebase: 10.1.4

AngularFire: 7.2.1

How to reproduce these conditions

Build the AngularFire Quickstart. https://github.com/angular/angularfire/blob/master/docs/install-and-setup.md

Step 7 fails.

Steps to set up and reproduce

This code is provided in the tutorial:

  constructor(firestore: AngularFirestore) {
    this.items = firestore.collection('items').valueChanges();
  }

That produces this error message:

src/app/app.component.ts:29:12 - error TS2339: Property 'firestore' does not exist on type 'AppComponent'.

I can fix the problem with this code:

  constructor(public firestore: AngularFirestore) {
    this.items = firestore.collection('items').valueChanges();
  }

Or with this code:

  constructor(protected firestore: AngularFirestore) {
    this.items = firestore.collection('items').valueChanges();
  }

This also works:

  constructor(private firestore: AngularFirestore) {
    this.items = firestore.collection('items').valueChanges();
  }

In other words, setting the constructor to public, protected, or private works. Setting nothing throws an error.

Debug output

src/app/app.component.ts:29:12 - error TS2339: Property 'firestore' does not exist on type 'AppComponent'.

Expected behavior

Not setting this and setting public should be the same, according to the TypeScript Handbook.

Actual behavior

Not setting this throws an error.

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