Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ packages/storage-types @sphippen

# Messaging Code
packages/messaging @gauntface @pinarx @mmermerkaya @alecmce @dwoffinden
packages/messaging-types @gauntface @pinarx @mmermerkaya @alecmce @dwoffinden
integration/messaging @gauntface @pinarx @mmermerkaya @alecmce @dwoffinden

# Auth Code
Expand Down
1 change: 0 additions & 1 deletion packages/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"typings": "dist/index.d.ts",
"dependencies": {
"@firebase/functions-types": "0.1.2",
"@firebase/messaging-types": "0.2.2",
"isomorphic-fetch": "2.2.1"
},
"nyc": {
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { FirebaseApp } from '@firebase/app-types';
import { _FirebaseApp } from '@firebase/app-types/private';
import { firebase } from '@firebase/app';
import { FirebaseMessaging } from '@firebase/messaging-types';
import { FirebaseMessaging } from '@firebase/messaging';

/**
* The metadata that should be supplied with function calls.
Expand Down
26 changes: 0 additions & 26 deletions packages/messaging-types/package.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/messaging-types/tsconfig.json

This file was deleted.

4 changes: 3 additions & 1 deletion packages/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import {
_FirebaseNamespace,
FirebaseServiceFactory
} from '@firebase/app-types/private';
import { FirebaseMessaging } from '@firebase/messaging-types';

import { SwController } from './src/controllers/sw-controller';
import { WindowController } from './src/controllers/window-controller';
import { FirebaseMessaging } from './src/interfaces/firebase-messaging';
import { ERROR_CODES, errorFactory } from './src/models/errors';

export { FirebaseMessaging } from './src/interfaces/firebase-messaging';

export function registerMessaging(instance: _FirebaseNamespace): void {
const messagingName = 'messaging';

Expand Down
1 change: 0 additions & 1 deletion packages/messaging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@firebase/app-types": "0.x"
},
"dependencies": {
"@firebase/messaging-types": "0.2.2",
"@firebase/util": "0.2.0",
"tslib": "1.9.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/src/controllers/controller-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { FirebaseApp } from '@firebase/app-types';
import { FirebaseServiceInternals } from '@firebase/app-types/private';
import { FirebaseMessaging } from '@firebase/messaging-types';
import {
CompleteFn,
ErrorFn,
Expand All @@ -26,6 +25,7 @@ import {
} from '@firebase/util';

import { isArrayBufferEqual } from '../helpers/is-array-buffer-equal';
import { FirebaseMessaging } from '../interfaces/firebase-messaging';
import { MessagePayload } from '../interfaces/message-payload';
import { TokenDetails } from '../interfaces/token-details';
import { ERROR_CODES, errorFactory } from '../models/errors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,32 @@
* limitations under the License.
*/

import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
import {
Observer,
Unsubscribe,
NextFn,
CompleteFn,
ErrorFn,
CompleteFn
NextFn,
Observer,
Unsubscribe
} from '@firebase/util';

export class FirebaseMessaging {
private constructor();
export interface FirebaseMessaging {
deleteToken(token: string): Promise<boolean>;
getToken(): Promise<string | null>;
onMessage(
// tslint:disable-next-line no-any The message payload can be anything.

Choose a reason for hiding this comment

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

Isn't object the better type for "I have no idea what this is, but I don't do anything specific with it"? And that's what the implementation seems to use anyway?

nextOrObserver: NextFn<object> | Observer<object>,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The implementation uses object because inside the SDK we don't (and shouldn't) access any properties of the payload. Like you said, we don't do anything specific with it.

The exported types are different, because the user should know and be able to access their payload's properties.

So this would work with any and wouldn't work with object (when --strict flag is on, because of strictFunctionTypes):

messaging.onMessage((payload: UserDefinedPayloadObjectType) => {
  const messageData = payload.someField;
  // Do stuff with payload.
});

I'm planning on eventually making this a MessagePayload and preventing the --strict errors, but I'm about to propose some changes to that type, so I think it's better to keep this as any for now and change it later.

Choose a reason for hiding this comment

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

Right, the type safety escape hatch is used because this isn't type safe, gotcha :/

Seems to me like the whole FirebaseMessaging interface should take a type parameter of the expected type, and then callers are expected to provide callbacks that handle precisely that type. In the meantime, carry on I guess :/

nextOrObserver: NextFn<any> | Observer<any>,
error?: ErrorFn,
completed?: CompleteFn
): Unsubscribe;
onTokenRefresh(
// tslint:disable-next-line no-any Not implemented yet.
nextOrObserver: NextFn<any> | Observer<any>,
error?: ErrorFn,
completed?: CompleteFn
): Unsubscribe;
requestPermission(): Promise<void>;
setBackgroundMessageHandler(
// tslint:disable no-any The message payload can be anything.
callback: (payload: any) => Promise<any> | void
): void;
useServiceWorker(registration: ServiceWorkerRegistration): void;
Expand Down