diff --git a/.changeset/eighty-coats-hide.md b/.changeset/eighty-coats-hide.md new file mode 100644 index 00000000000..b70571fc79e --- /dev/null +++ b/.changeset/eighty-coats-hide.md @@ -0,0 +1,5 @@ +--- +'@firebase/database-types': patch +--- + +Updated typings for Reference methods diff --git a/packages/database-compat/src/api/Reference.ts b/packages/database-compat/src/api/Reference.ts index e0ecfaee049..3f9bb63b8ff 100644 --- a/packages/database-compat/src/api/Reference.ts +++ b/packages/database-compat/src/api/Reference.ts @@ -601,7 +601,7 @@ export class Reference extends Query implements Compat { set( newVal: unknown, onComplete?: (error: Error | null) => void - ): Promise { + ): Promise { validateArgCount('Reference.set', 1, 2, arguments.length); validateCallback('Reference.set', 'onComplete', onComplete, true); const result = set(this._delegate, newVal); @@ -617,7 +617,7 @@ export class Reference extends Query implements Compat { update( values: object, onComplete?: (a: Error | null) => void - ): Promise { + ): Promise { validateArgCount('Reference.update', 1, 2, arguments.length); if (Array.isArray(values)) { @@ -650,7 +650,7 @@ export class Reference extends Query implements Compat { newVal: unknown, newPriority: string | number | null, onComplete?: (a: Error | null) => void - ): Promise { + ): Promise { validateArgCount('Reference.setWithPriority', 2, 3, arguments.length); validateCallback( 'Reference.setWithPriority', @@ -669,7 +669,7 @@ export class Reference extends Query implements Compat { return result; } - remove(onComplete?: (a: Error | null) => void): Promise { + remove(onComplete?: (a: Error | null) => void): Promise { validateArgCount('Reference.remove', 0, 1, arguments.length); validateCallback('Reference.remove', 'onComplete', onComplete, true); @@ -733,7 +733,7 @@ export class Reference extends Query implements Compat { setPriority( priority: string | number | null, onComplete?: (a: Error | null) => void - ): Promise { + ): Promise { validateArgCount('Reference.setPriority', 1, 2, arguments.length); validateCallback('Reference.setPriority', 'onComplete', onComplete, true); diff --git a/packages/database-types/index.d.ts b/packages/database-types/index.d.ts index 9d4cce3742d..680a4a540b8 100644 --- a/packages/database-types/index.d.ts +++ b/packages/database-types/index.d.ts @@ -125,24 +125,24 @@ 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; + remove(onComplete?: (a: Error | null) => void): Promise; root: Reference; - set(value: any, onComplete?: (a: Error | null) => any): Promise; + set(value: any, onComplete?: (a: Error | null) => void): Promise; setPriority( priority: string | number | null, - onComplete: (a: Error | null) => any - ): Promise; + onComplete: (a: Error | null) => void + ): Promise; setWithPriority( newVal: any, newPriority: string | number | null, - onComplete?: (a: Error | null) => any - ): Promise; + onComplete?: (a: Error | null) => void + ): Promise; 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; - update(values: Object, onComplete?: (a: Error | null) => any): Promise; + ): Promise; + update(values: Object, onComplete?: (a: Error | null) => void): Promise; } export interface ServerValue { @@ -150,6 +150,11 @@ export interface ServerValue { increment(delta: number): Object; } +export interface TransactionResult { + committed: boolean; + snapshot: DataSnapshot; +} + export interface ThenableReference extends Reference, Pick, 'then' | 'catch'> {} diff --git a/packages/firebase/compat/index.d.ts b/packages/firebase/compat/index.d.ts index 8e55d69ffd5..d28e37f48e6 100644 --- a/packages/firebase/compat/index.d.ts +++ b/packages/firebase/compat/index.d.ts @@ -7082,7 +7082,7 @@ declare namespace firebase.database { * complete. * @return Resolves when remove on server is complete. */ - remove(onComplete?: (a: Error | null) => any): Promise; + remove(onComplete?: (a: Error | null) => void): Promise; /** * The root `Reference` of the Database. * @@ -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; + set(value: any, onComplete?: (a: Error | null) => void): Promise; /** * Sets a priority for the data at this Database location. * @@ -7172,8 +7172,8 @@ declare namespace firebase.database { */ setPriority( priority: string | number | null, - onComplete: (a: Error | null) => any - ): Promise; + onComplete: (a: Error | null) => void + ): Promise; /** * Writes data the Database location. Like `set()` but also specifies the * priority for that data. @@ -7187,8 +7187,8 @@ declare namespace firebase.database { setWithPriority( newVal: any, newPriority: string | number | null, - onComplete?: (a: Error | null) => any - ): Promise; + onComplete?: (a: Error | null) => void + ): Promise; /** * Atomically modifies the data at this location. * @@ -7280,9 +7280,9 @@ declare namespace firebase.database { a: Error | null, b: boolean, c: firebase.database.DataSnapshot | null - ) => any, + ) => void, applyLocally?: boolean - ): Promise; + ): Promise; /** * Writes multiple values to the Database at once. * @@ -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; + update( + values: Object, + onComplete?: (a: Error | null) => void + ): Promise; + } + + interface TransactionResult { + /** + * Whether the transaction was successfully committed. + */ + committed: boolean; + /** + * The resulting data snapshot. + */ + snapshot: DataSnapshot; } interface ThenableReference