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

Conversation

rhodgkins
Copy link
Contributor

Fixes #6071. I've also update the return type for the onComplete handler that the methods also accept.

I've copied the comments for the TransactionResult interface from the corresponding @firebase/database package:

export class TransactionResult {
/** @hideconstructor */
constructor(
/** Whether the transaction was successfully committed. */
readonly committed: boolean,
/** The resulting data snapshot. */
readonly snapshot: DataSnapshot
) {}

@changeset-bot
Copy link

changeset-bot bot commented Mar 22, 2022

🦋 Changeset detected

Latest commit: 8221684

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/database-types Patch
@firebase/database-compat Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@hsubox76 hsubox76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, in addition to the small nit about readonly (see comments), can you also add a changeset? To do this, run yarn changeset in the root of the repo and follow the prompts (select database-types as it suggests, then skip the "major" and "minor" options to let it default to "patch", then write a brief change note like "Updated typings for Reference methods"

}

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

export interface TransactionResult {
readonly committed: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properties actually aren't readonly on the database-compat TransactionResult class, which is the only place this type will be applied, so it might be best to keep it looser and omit the readonly keyword:

constructor(public committed: boolean, public snapshot: DataSnapshot) {}

/**
* Whether the transaction was successfully committed.
*/
readonly committed: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment regarding readonly.

@rhodgkins
Copy link
Contributor Author

@hsubox76 thanks for the review, readonlys removed and change set added 👍

@hsubox76
Copy link
Contributor

hsubox76 commented Mar 25, 2022

It seems like the readonly has been removed from firebase/compat/index.d.ts but not from database-types/index.d.ts, is that the case or is it a Github refresh issue on my end?

Edit: oops, sorry, missed this earlier but the return types on the methods in database-compat are actually Promise<unknown>, not Promise<void>:

remove(onComplete?: (a: Error | null) => void): Promise<unknown> {

Which you can see is causing problems in the CI tests. I actually think unknown is incorrect and your typings are correct, and database-compat/src/api/Reference.ts should be changed so the methods in conflict (update, remove, getPriority, etc) return Promise<void>. If this is getting to be too much of a headache for you, I can take this, but it's totally up to you.

@rhodgkins
Copy link
Contributor Author

It seems like the readonly has been removed from firebase/compat/index.d.ts but not from database-types/index.d.ts, is that the case or is it a Github refresh issue on my end?

@hsubox76 ah sorry, totally missed that 🙈

database-compat/src/api/Reference.ts should be changed so the methods in conflict (update, remove, getPriority, etc) return Promise<void>

I'll have a go at changing those and see if that works :)

@rhodgkins rhodgkins requested a review from hsubox76 March 25, 2022 20:21
@rhodgkins
Copy link
Contributor Author

@hsubox76 I've updated that file but there's still CI failures but its in a file I've not touched (I think anyway) - ERROR in /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/database/src/api/Database.ts, is something else needed?

@hsubox76
Copy link
Contributor

@hsubox76 I've updated that file but there's still CI failures but its in a file I've not touched (I think anyway) - ERROR in /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/database/src/api/Database.ts, is something else needed?

It was a flaky test. I re-ran it and it passed. Everything looks good, will merge!

@hsubox76 hsubox76 merged commit 1c37b5e into firebase:master Mar 28, 2022
@rhodgkins
Copy link
Contributor Author

Ah great, thanks 👍

@rhodgkins rhodgkins deleted the fix_6071 branch March 28, 2022 17:48
@google-oss-bot google-oss-bot mentioned this pull request Apr 12, 2022
@firebase firebase locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rtdb: Reference#transaction return type
2 participants