Skip to content

Fix the type annotations in the RTDB Query.on/off/once API. #1204

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 5 commits into from
Apr 24, 2019

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Sep 5, 2018

This fixes the nullability annotations in the RTDB Query.on/off API. The callback can be optional, but not the DataSnapshot. This is a breaking typing cleanup (as some types used to take "null"), but this updates the TS types to match the JS reference docs.

Fixes: #1188

@schmidt-sebastian schmidt-sebastian changed the title Fix the nullability annotations in the RTDB Query.on/off API. Fix the types annotations in the RTDB Query.on/off/once API. Sep 5, 2018
@schmidt-sebastian schmidt-sebastian changed the title Fix the types annotations in the RTDB Query.on/off/once API. Fix the type annotations in the RTDB Query.on/off/once API. Sep 5, 2018
callback?: (a: DataSnapshot, b?: string | null) => any,
context?: Object | null
): any;
callback?: (a: DataSnapshot, b?: string) => any,
Copy link
Contributor

Choose a reason for hiding this comment

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

b (aka prevChildName) will be null in the case of child_added events where there's no predecessor.

cancelCallbackOrContext?: Object | null,
context?: Object | null
): (a: DataSnapshot | null, b?: string) => any;
callback: (a: DataSnapshot, b?: string) => any,
Copy link
Contributor

Choose a reason for hiding this comment

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

b (aka prevChildName) will be null in the case of child_added events where there's no predecessor.

@@ -65,7 +65,7 @@ export class DataEvent implements Event {
| ' child_removed',
public eventRegistration: EventRegistration,
public snapshot: DataSnapshot,
public prevName?: string | null
public prevName?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

can be null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, you are obviously right here and I fixed the typing to allow for this value to be null, but I am a little confused why

change.prevName = eventCache.getPredecessorChildName(
compiles. I am going to guess it wouldn't with strictNullChecks.

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt-nullability branch 2 times, most recently from 1e05d59 to 6ed946c Compare April 12, 2019 21:56
Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

I "overhauled" this PR. There are a bunch of inconsistencies in our typings, which make touching the API types a bit confusing. We should probably invest a little bit of time and enable strictNullChecks.

@@ -65,7 +65,7 @@ export class DataEvent implements Event {
| ' child_removed',
public eventRegistration: EventRegistration,
public snapshot: DataSnapshot,
public prevName?: string | null
public prevName?: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, you are obviously right here and I fixed the typing to allow for this value to be null, but I am a little confused why

change.prevName = eventCache.getPredecessorChildName(
compiles. I am going to guess it wouldn't with strictNullChecks.

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

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

LGTM

@mikelehen
Copy link
Contributor

FYI- Still LGTM after changelog addition.

@schmidt-sebastian
Copy link
Contributor Author

This will be merged into the Firebase I/O release as it contains minor breaking changes.

@schmidt-sebastian
Copy link
Contributor Author

@Feiyang1 Can you merge this with the version bump?

@schmidt-sebastian schmidt-sebastian merged commit e50b070 into master Apr 24, 2019
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt-nullability branch April 24, 2019 21:33
schmidt-sebastian added a commit that referenced this pull request Apr 24, 2019
Feiyang1 pushed a commit that referenced this pull request May 1, 2019
zijianjoy pushed a commit that referenced this pull request May 24, 2019
@firebase firebase locked and limited conversation to collaborators Oct 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type mismatch between Query#on and Query#off
4 participants