1

I am messing around with modules in my typescript react project. Trying to get them to work. I declared my async function in my .ts file with types as so here:

//Library Imports
//Firestore SDK
import {
  getFirestore,
  collection,
  getDocs,
  setDoc,
  doc,
  addDoc,
  getDoc,
} from "firebase/firestore/lite";
//Firestore Config module
import { fireApp } from "./FirestoreConfig";

const fireData = getFirestore(fireApp);

//Get all documents from collection
const getAllDocs = async (Collection: string): Promise<any[]> => {
  let baseQuery = await getDocs(collection(fireData, Collection));
  let docs: any[] = [];
  baseQuery.forEach((doc) => docs.push(doc.data()));
  return docs;
};

export { getAllDocs };

I then import "getAllDocs" in my react app.tsx and I'm getting the error enter image description here

So I'm trying to use a d.ts file to define the type of my function, and I can't get it working. my d.ts file looks like this. This doesn't fix the issue.

declare module "getAllDocs" {
  export default function getAllDocs(Collection: string): Promise<any[]>;
}

How do I properly type the function to remove the error? I don't want to ignore the error. The d.ts file is in the exact same directory as the module I am trying to export. Any help would be greatly appreciated.

  • 1
    You don't need to write your own `.d.ts` files for your own functions. TypeScript will generate those for you automatically. – Dai Feb 01 '22 at 21:01
  • Okay, so how can I fix the error? – NickLeylandMedia Feb 01 '22 at 21:02
  • Why are you using `PascalCase` for parameters? That's wrong... so your `(Collection: string)` should be `(collection: string)` - though I know that's conflicting with your imported `collection` function, so give it a name like `items` or `strings` or something. – Dai Feb 01 '22 at 21:03
  • None of this is the core issue, can you please help with my actual issue? Changing the case does not fix the issue. – NickLeylandMedia Feb 01 '22 at 21:05
  • 1
    Have you seen this? https://stackoverflow.com/questions/55370851/how-to-fix-binding-element-children-implicitly-has-an-any-type-ts7031 – Dai Feb 01 '22 at 21:05
  • 1
    Well. I'm stupid. In my app.tsx file I had the getAllDocs being passed like you would pass a prop function. I removed it and no more errors! – NickLeylandMedia Feb 01 '22 at 21:11

0 Answers0