What is the proper way to implement Firebase getDoc in Vue with vue-concurrency?

I am currently in the process of developing a TypeScript Vue composable that utilizes Firebase and the vue-concurrency library.

According to the documentation, I need to explicitly type any intermediate values that are yielded.

I am facing a challenge while trying to type a Firebase getDoc call, as Eslint is flagging an error stating

Unsafe assignment of an 'any' value
that I need to resolve:

import { db } from 'src/firebase/config';
import {
  doc,
  getDoc,
  // DocumentData,
  DocumentSnapshot,
} from 'firebase/firestore';
import { useTask } from 'vue-concurrency';

const getDocumentTask = useTask(function* (
  signal,
  collectionName: string,
  documentId: string
) {
  const documentReference = doc(db, collectionName, documentId);
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  const response: DocumentSnapshot = yield getDoc(documentReference); // <-- Eslint error here
  const document = {
    ...response.data(),
    id: response.id,
  };
  return document;
});

export default getDocumentTask;

Answer №1

After some digging, I finally came across the solution (at least for my situation).

Substitute

'firebase/firestore'

with

'firebase/firestore/lite'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way for me to create a link that is specifically for printing on 3D printers, rather than a link for downloading the

I have a project with a company that sells 3D printable models (.STL) online. They want to add specific models to their digital inventory without allowing direct downloads. Instead, once a customer purchases a model, they should be able to immediately pr ...

Unlock the Power of Angular with Custom Decorators: Accessing ElementRef Made Easy

I am currently working on implementing a decorator for Host CSS Variable Binding in Angular5. However, I am facing difficulties in properly implementing it with the given code. Is there a way to define ElementRef from within the decorator itself? export f ...

Error encountered while building with Next.js using TypeScript: SyntaxError - Unexpected token 'export' in data export

For access to the code, click here => https://codesandbox.io/s/sweet-mcclintock-dhczx?file=/pages/index.js The initial issue arises when attempting to use @iconify-icons/cryptocurrency with next.js and typescript (specifically in typescript). SyntaxErr ...

Creating a DIV element in Angular 5 component rather than using a new tag

Is there a way to instruct Angular to generate a DIV instead of another tag when inserting a component into a router-outlet? Currently, the component code looks like this: import { Component, OnInit, ViewEncapsulation } from '@angular/core'; @C ...

SolidJS does not support reactivity for arrays of objects

I've been scratching my head trying to figure out why this code isn't working as expected. I'm simply updating an object and expecting it to be refreshed in the DOM, but for some reason, that's not happening. The console log confirms th ...

Handling type errors with React Typescript MuiAccordion OnChange event handler

I'm a beginner in typescript and seeking advice on defining the type for an event handler. I have a component that utilizes material ui Accordion and triggers the handler from a container. Therefore, I need to specify the type of handleChange in my co ...

Limit the elements in an array within a specified range of dates

Currently, I am working on implementing a filter functionality for a data array used in a LineChart within my Angular application using TypeScript. The structure of the data array is as follows: var multi = [ { "name": "test1", "series": [ ...

Guide on developing a personalized validation system with Vuetify regulations for verifying the presence of an item

I'm currently working on my first CRUD web app using Vue 2 + Vuetify, but I've hit a roadblock while trying to add validation to a form. Specifically, I need to ensure that no item with the same title already exists in the database. You can view ...

Generating TypeScript declarations for legacy CommonJS dependencies with the correct "module" setting

One of my challenges involves creating type declarations for outdated dependencies that produce CJS modules and lack typings. An example is the aabb-3d module (although this issue isn't specific to that particular module). To generate the declaration ...

I am having difficulty accessing the values stored in my cardTiles variable

I am facing an issue with a variable called cardTiles in my Angular 9 component. The variable is defined as cardTitles:Product[] = []; The Product class is defined as follows export class Product{ productName: string;} When I console.log(this.cardTi ...

The error message "Unable to access property 'open' of an undefined menu" is being displayed in a TypeScript code

I am facing an issue with the action in my menu. For this project, I am using a material menu and icons. The main menu code appears as follows: <mat-menu #rootMenu="matMenu" [overlapTrigger]="false"> <ng-template matMenuContent let-element="ele ...

Ziggy - Inertia js vue app will not be mounted at all when we import a route from 'ziggy' in app.js

Currently, I am working on a project that involves Laravel, Ziggy, Inertia, and Vue. Interestingly, I encountered an issue where I couldn't integrate Ziggy with Vue as recommended in their documentation. Below is my app.js file for reference. It' ...

What is the method for extracting date of birth data from .NET to Angular?

Struggling to fetch the date of birth from the database where it has been stored. After searching through multiple resources online, I am still unsure about how to accomplish this task. export class DetailsEmployeeComponent implements OnInit{ employeeD ...

What is the reason Vue does not execute or update a computed property that contains a reference to 'this' within a filter function?

My question pertains to a select box that is linked to a Vue computed property. I am puzzled by the discrepancy in functionality between two of my computed property attempts. <select> <option v-for="option in filteredItems">{{option.descriptio ...

Can an onSnapshot event be set up for an array in order to track changes?

In my system, each user is associated with multiple groups. Each user's group membership is stored as an array within their user document. Additionally, there is a tasks collection where each task contains an array of authorizedGroups that correspond ...

Unclear value of button when being passed

In my Welcome.html file, I am attempting to send the value of a button to a function that simply logs that value. This function is located in a functions class that has been imported into my welcome.ts file. <ion-content padding id="page1"> <h1 ...

Having trouble generating a bin executable for my npm package

Referencing: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin I am attempting to generate a "binary" for my npm package. The structure of my package.json is as follows: { "name": "@internal/my-exe", "version": "0.0.0", "type": "commo ...

Encountering an illegal invocation type error when clicking on the search icon within a Vue component

I keep encountering an "illegal invocation" error in the console whenever I try to click on the search icon. 'focus' called on an object that does not implement interface HTMLElement. This error seems to occur intermittently. <div class=" ...

When using Next.js, I have found that the global.css file only applies styles successfully when the code is pasted directly into the page.tsx file. However, when attempting to

I recently started exploring nextjs and came across this video "https://www.youtube.com/watch?v=KzqNLDMSdMc&ab_channel=TheBraveCoders" This is when I realized that the CSS styles were not being applied to HeaderTop (the first component cre ...

When using the TypeScript && operator, the resulting type is not determined by the second operand

Several past discussions on SO have touched upon the concept that the inferred type from && is based on the last expression. TypeScript’s failure to detect union type with an && operator Uncovering the reason behind the && opera ...