Skip to content

compilation errors every time a new version of firebase is used #3245

Open

Description

@jnizet

I'm sorry if this issue doesn't actually have anything to do with Angularfire, and if it looks more like a question than an actual issue.
Feel free to close this issue if you feel it doesn't belong here.

I use yarn and have configured renovate bot on my project. So every time a new version of Firebase is released, it makes a commit which upgrades the version. And almost every time it does that (like in this PR, which upgrades from firebase 9.8.4 to firebase 9.9.0), the code, which compiled fine before, dosn't compile anymore, with errors such as the following one:

Error: Error: src/app/activity/activity.service.ts:185:5 - error TS2322: Type 'Observable<(string | FieldValue)[]>' is not assignable to type 'Observable<string[]>'.
  Type '(string | FieldValue)[]' is not assignable to type 'string[]'.
    Type 'string | FieldValue' is not assignable to type 'string'.
      Type 'FieldValue' is not assignable to type 'string'.
185     return collectionData(this.animatorCollection).pipe(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186       first(),
    ~~~~~~~~~~~~~~
... 
193       )
    ~~~~~~~
194     );

for code looking like

export interface Animator {
  name: string;
}

// ...
  private animatorCollection: CollectionReference<Animator>;
// ...
  suggestAnimators(text: string): Observable<Array<string>> {
    const query = text.toLowerCase();
    return collectionData(this.animatorCollection).pipe(
      first(),
      map(animators =>
        animators
          .filter(a => a.name.toLowerCase().includes(query))
          .map(a => a.name)
          .sort()
          .slice(0, 10)
      )
    );
  }

So suddenly, for a reason that I ignore, the compiler doesn't infer the types correctly.

The fix is relatively simple: delete the yarn.lock file, and run yarn again.

But I wonder what I should do to avoid having to do that every time, and would like to understand why this strange behavior happens.

Activity

  1. google-oss-bot commented on Jul 8, 2022

    @google-oss-bot

    This issue does not seem to follow the issue template. Make sure you provide all the required information.

  2. salifukayta commented on Nov 8, 2024

    @salifukayta

    Hello, I have the same problem when upgrading @angular/fire from 7.6.1 to 17.1.0
    I didn't find any migration documentation.

    the snippet below worked in 7.6.1

      async getTask(id: string): Promise<TaskModel> {
        const taskRef = doc(getFirestore(), "task/1")
          .withConverter(taskConverter);
    
        const taskSnapshot = await getDoc(taskRef);
    
        return taskSnapshot.data();  //  <-- error on this line
      }

    But now in 17.1.0, I have Type 'FieldValue' is not assignable to type 'string'. for each field.
    Can you help please ? any idea ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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