This is currently open as issue #2378 (as of May, 2024). Until that is resolved and the project provides official types, you can manually create a module declaration with just enough type definitions to access a single command like this:
Create a new file types/FirebaseTools.d.ts
. I determined the parameter names and types by looking at the output of firebase <command> -h
.
declare module "firebase-tools" {
// here we expose just enough to get the database:remove command to work in Typescript
interface FirebaseClient {
database: {
remove: (path: string, options?: DatabaseRemoveOptions) => Promise<void>;
};
}
const client: FirebaseClient;
export default client;
// global program options
interface FirebaseToolsOptions {
/** the Google account to use for authorization */
account?: string;
/** the Firebase project to use for this command */
project?: string;
/** output JSON instead of text, also triggers non-interactive mode */
json?: boolean;
/** error out of the command instead of waiting for prompts */
"non-interactive"?: boolean;
/** print verbose debug output and keep a debug log file */
debug?: boolean;
}
// options specific to database:remove
interface DatabaseRemoveOptions extends FirebaseToolsOptions {
/** bypass confirmation prompt */
force?: boolean;
/** use the database <instance>.firebaseio.com (if omitted, use default instance) */
instance?: string;
/** suppress any Cloud functions triggered by this operation */
"disable-triggers"?: boolean;
}
}
Then add a mapping to paths
inside tsconfig.json
{
// ...
"compilerOptions": {
// ...
"paths": {
"firebase-tools": ["./types/FirebaseTools.d.ts"],
},
},
}
Now you can import the package as a module and access the particular command described in the type definition:
import FirebaseCLI from "firebase-tools";
// ...
await FirebaseCLI.database.remove("/foo/bar", {
"non-interactive": true,
force: true,
"disable-triggers": true,
});