Skip to content

Updated typings for database methods #6090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-coats-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/database-types': patch
---

Updated typings for Reference methods
10 changes: 5 additions & 5 deletions packages/database-compat/src/api/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ export class Reference extends Query implements Compat<ModularReference> {
set(
newVal: unknown,
onComplete?: (error: Error | null) => void
): Promise<unknown> {
): Promise<void> {
validateArgCount('Reference.set', 1, 2, arguments.length);
validateCallback('Reference.set', 'onComplete', onComplete, true);
const result = set(this._delegate, newVal);
Expand All @@ -617,7 +617,7 @@ export class Reference extends Query implements Compat<ModularReference> {
update(
values: object,
onComplete?: (a: Error | null) => void
): Promise<unknown> {
): Promise<void> {
validateArgCount('Reference.update', 1, 2, arguments.length);

if (Array.isArray(values)) {
Expand Down Expand Up @@ -650,7 +650,7 @@ export class Reference extends Query implements Compat<ModularReference> {
newVal: unknown,
newPriority: string | number | null,
onComplete?: (a: Error | null) => void
): Promise<unknown> {
): Promise<void> {
validateArgCount('Reference.setWithPriority', 2, 3, arguments.length);
validateCallback(
'Reference.setWithPriority',
Expand All @@ -669,7 +669,7 @@ export class Reference extends Query implements Compat<ModularReference> {
return result;
}

remove(onComplete?: (a: Error | null) => void): Promise<unknown> {
remove(onComplete?: (a: Error | null) => void): Promise<void> {
validateArgCount('Reference.remove', 0, 1, arguments.length);
validateCallback('Reference.remove', 'onComplete', onComplete, true);

Expand Down Expand Up @@ -733,7 +733,7 @@ export class Reference extends Query implements Compat<ModularReference> {
setPriority(
priority: string | number | null,
onComplete?: (a: Error | null) => void
): Promise<unknown> {
): Promise<void> {
validateArgCount('Reference.setPriority', 1, 2, arguments.length);
validateCallback('Reference.setPriority', 'onComplete', onComplete, true);

Expand Down
23 changes: 14 additions & 9 deletions packages/database-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,36 @@ export interface Reference extends Query {
onDisconnect(): OnDisconnect;
parent: Reference | null;
push(value?: any, onComplete?: (a: Error | null) => any): ThenableReference;
remove(onComplete?: (a: Error | null) => any): Promise<any>;
remove(onComplete?: (a: Error | null) => void): Promise<void>;
root: Reference;
set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
set(value: any, onComplete?: (a: Error | null) => void): Promise<void>;
setPriority(
priority: string | number | null,
onComplete: (a: Error | null) => any
): Promise<any>;
onComplete: (a: Error | null) => void
): Promise<void>;
setWithPriority(
newVal: any,
newPriority: string | number | null,
onComplete?: (a: Error | null) => any
): Promise<any>;
onComplete?: (a: Error | null) => void
): Promise<void>;
transaction(
transactionUpdate: (a: any) => any,
onComplete?: (a: Error | null, b: boolean, c: DataSnapshot | null) => any,
onComplete?: (a: Error | null, b: boolean, c: DataSnapshot | null) => void,
applyLocally?: boolean
): Promise<any>;
update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
): Promise<TransactionResult>;
update(values: Object, onComplete?: (a: Error | null) => void): Promise<void>;
}

export interface ServerValue {
TIMESTAMP: Object;
increment(delta: number): Object;
}

export interface TransactionResult {
committed: boolean;
snapshot: DataSnapshot;
}

export interface ThenableReference
extends Reference,
Pick<Promise<Reference>, 'then' | 'catch'> {}
Expand Down
32 changes: 23 additions & 9 deletions packages/firebase/compat/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7082,7 +7082,7 @@ declare namespace firebase.database {
* complete.
* @return Resolves when remove on server is complete.
*/
remove(onComplete?: (a: Error | null) => any): Promise<any>;
remove(onComplete?: (a: Error | null) => void): Promise<void>;
/**
* The root `Reference` of the Database.
*
Expand Down Expand Up @@ -7160,7 +7160,7 @@ declare namespace firebase.database {
* complete.
* @return Resolves when write to server is complete.
*/
set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
set(value: any, onComplete?: (a: Error | null) => void): Promise<void>;
/**
* Sets a priority for the data at this Database location.
*
Expand All @@ -7172,8 +7172,8 @@ declare namespace firebase.database {
*/
setPriority(
priority: string | number | null,
onComplete: (a: Error | null) => any
): Promise<any>;
onComplete: (a: Error | null) => void
): Promise<void>;
/**
* Writes data the Database location. Like `set()` but also specifies the
* priority for that data.
Expand All @@ -7187,8 +7187,8 @@ declare namespace firebase.database {
setWithPriority(
newVal: any,
newPriority: string | number | null,
onComplete?: (a: Error | null) => any
): Promise<any>;
onComplete?: (a: Error | null) => void
): Promise<void>;
/**
* Atomically modifies the data at this location.
*
Expand Down Expand Up @@ -7280,9 +7280,9 @@ declare namespace firebase.database {
a: Error | null,
b: boolean,
c: firebase.database.DataSnapshot | null
) => any,
) => void,
applyLocally?: boolean
): Promise<any>;
): Promise<TransactionResult>;
/**
* Writes multiple values to the Database at once.
*
Expand Down Expand Up @@ -7329,7 +7329,21 @@ declare namespace firebase.database {
* complete.
* @return Resolves when update on server is complete.
*/
update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
update(
values: Object,
onComplete?: (a: Error | null) => void
): Promise<void>;
}

interface TransactionResult {
/**
* Whether the transaction was successfully committed.
*/
committed: boolean;
/**
* The resulting data snapshot.
*/
snapshot: DataSnapshot;
}

interface ThenableReference
Expand Down