Skip to content

Update Webpush types in Messaging #286

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 1 commit into from
Jun 19, 2018
Merged

Conversation

mmermerkaya
Copy link
Contributor

@mmermerkaya mmermerkaya requested a review from hiranya911 June 1, 2018 15:11
@hiranya911
Copy link
Contributor

@mmermerkaya thanks for putting this together. A couple of high level notes:

  1. You should also update the typings in index.d.ts file.
  2. We usually provide typed setters for known fields (see how the Aps type is defined). Can we do something similar here? At very least, we should do something like the following to keep backward compatibility:
{
  title?: string;
  body?: string;
  icon?: string;
  {[key: string]: any};
}

@mmermerkaya
Copy link
Contributor Author

Thanks for the review!

TypeScript already includes Web Notification typings, but they are in the DOM library: https://github.com/Microsoft/TypeScript/blob/v2.9.1/lib/lib.dom.d.ts#L941

If we add "dom" to lib in tsconfig I can just refer to those types, and they would get updated automatically. WDYT?

@hiranya911
Copy link
Contributor

Does that mean it's part of the standard TypeScript distribution? Sounds reasonable to me.

@hiranya911
Copy link
Contributor

hiranya911 commented Jun 1, 2018

You should also use the same type def in the messaging.ts file (when declaring the WebpushConfig type)

Edit: Btw it looks like some fields are missing in NotificationOptions. I don't see title, badge, actions and a couple of others.

@mmermerkaya mmermerkaya force-pushed the mmermerkaya-update-webpush branch from baa9d76 to 6a3db24 Compare June 1, 2018 18:54
@mmermerkaya
Copy link
Contributor Author

Yep, it is part of TS. Missing options are already fixed here, just not released yet.

I've done the same change in index.d.ts. I see that they are defined as types in index.d.ts and as interfaces in messaging.ts. It's recommended to use interfaces instead of types: http://go/tsstyle#interfaces-vs-type-aliases

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

LGTM

I'll run this by the API review team real quick before merging, since it's technically an API change. Any idea when the dom typing update will be released?

@hiranya911 hiranya911 self-assigned this Jun 1, 2018
@mmermerkaya
Copy link
Contributor Author

Ping, I think we can merge this now.

The DOM typing update will be in TS 3.0: microsoft/TypeScript-DOM-lib-generator#438 (comment)

@hiranya911
Copy link
Contributor

@mmermerkaya I want to revisit the decision to extend from NotificationOptions. It seems the REST API explicitly avoided doing so since that API is likely to change, and not under our control. Can this be a concern here? Are we just better off with the following?

interface WebpushNotification {
     title?: string;
    body?: string;
    icon?: string;
    [key: string]: string;
};

@mmermerkaya
Copy link
Contributor Author

We did that because we didn't want to keep changing our API whenever the spec changes. So we decided not to do any server side validation of the WebpushNotification payload and pass it directly to the browser (as NotificationOptions). Since TypeScript already has a NotificationOptions type that is following the spec, it makes sense to use that type here.

@hiranya911
Copy link
Contributor

But that means changes in NotificationOptions can break our semver contract. Or may be it's not an issue since we already export some GCS and Firestore types in our public API as well.

@jshcrowthe what do you think?

@jshcrowthe
Copy link

I think I'm actually in favor of using the NotificationOptions interface directly rather than extend it. I'm with @mmermerkaya that the typings should be spec based and one of the spec tenants is "don't break the web" so I'm not too concerned w/ them breaking us (in such a way that we'd need a semver update).

However I think it makes sense to just call this a NotificationOptions and when the update drops we inherit the benefit. Adding a generic catchall isn't really much different than just casting a specific instance that uses properties that aren't listed to an any.

@mmermerkaya
Copy link
Contributor Author

Extending from NotificationOptions is just a way to provide hints to the user. The API isn't actually restricted to NotificationOptions. It accepts all key-value pairs. It doesn't make sense to restrict what the user can use to NotificationOptions (which is currently not even up to date with the spec) when we explicitly decided to let the user send any payload they want. Also, title isn't part of the NotificationOptions type (because of how the API works), but it is a property that we use in the FCM SDK.

Another point is that we are not actually shipping NotificationOptions. That comes with TS, so the type will only change if the developers update their TS versions.

Casting to any is not something the user should have to do to use our API. We should not be encouraging the use of any, which is against Google TS style.

@hiranya911
Copy link
Contributor

WebpushNotification is an existing type in our API so we cannot really replace it at this time. But overall this makes me feel better about reusing the existing NotificationOptions type. I will merge the PR as is shortly.

@mmermerkaya
Copy link
Contributor Author

mmermerkaya commented Jun 18, 2018

Ping. I can merge this myself but I want to make sure that it's okay with you.

@hiranya911 hiranya911 merged commit 53b854f into master Jun 19, 2018
@hiranya911
Copy link
Contributor

This is causing one of our release verification scripts to fail. Looks like the users of firebase-admin now must have dom in their tsconfig. That doesn't sound right.

@mmermerkaya mmermerkaya deleted the mmermerkaya-update-webpush branch July 13, 2018 14:02
@mmermerkaya mmermerkaya mentioned this pull request Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants