Skip to content

Fix messaging being optional and isSupported type definitions #793

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
May 15, 2018

Conversation

mmermerkaya
Copy link
Contributor

@mmermerkaya mmermerkaya commented May 9, 2018

Fixes TS thinking firebase.messaging() method is optional after importing 'firebase/messaging' (removes the ?). This should be done in other packages as well, unless there's a reason for the discrepancy between importing from 'firebase' and from 'firebase/packageName' that I don't know about.

Modifies messaging.isSupported() so it is a namespace export and not a property on the factory function, which is not actually exported. Fixes types accordingly.

Copy link

@dwoffinden dwoffinden left a comment

Choose a reason for hiding this comment

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

messaging?: {
(app?: FirebaseApp): types.FirebaseMessaging;
Messaging: typeof types.FirebaseMessaging;
messaging: {

Choose a reason for hiding this comment

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

Soo... @firebase/messaging is optional; you can use @firebase/database etc. but not messaging just fine.
firebase the metapackage bundles everything together, cool.
But if you just depend on @firebase/messaging, it would monkey-patch @firebase/app-types to add itself optionally? weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are all optional (you can import them or not), but if you import them, then the namespace exists (and the type should not be "optional" anymore). I'm not sure why that ? ever existed, I'm hoping @jshcrowthe has an idea.

import {
_FirebaseNamespace,
FirebaseServiceFactory
} from '@firebase/app-types/private';

Choose a reason for hiding this comment

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

It'd be really nice to have a test that works like the docs suggests a user to, i.e.

import firebase from '@firebase/app';
import '@firebase/messaging'
// Do stuff w/ `firebase` and `firebase.messaging`

rather than poking at the internals like this :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. The tests need an overhaul (not just here). I'll get to that soon™.

@mmermerkaya mmermerkaya requested a review from alecmce May 14, 2018 11:05
Fixes firebase.messaging() method being optional in TS types.

Modifies isSupported so it is a namespace export and not a property on the factory function, which is not actually exported.
@mmermerkaya mmermerkaya force-pushed the mmermerkaya-fix-types branch 3 times, most recently from 9e1a304 to 4196fab Compare May 14, 2018 11:33
Copy link
Contributor

@jshcrowthe jshcrowthe left a comment

Choose a reason for hiding this comment

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

This LGTM 👍

@mmermerkaya mmermerkaya merged commit 6a95a7a into master May 15, 2018
@jshcrowthe jshcrowthe deleted the mmermerkaya-fix-types branch May 15, 2018 18:52
@firebase firebase locked and limited conversation to collaborators Oct 20, 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.

4 participants