Skip to content

Commit

Permalink
Update Observer and Messaging types to match internal types (#786)
Browse files Browse the repository at this point in the history
* Fix Observer and Messaging types

* [AUTOMATED]: Prettier Code Styling

* Add second generic with Error as default
  • Loading branch information
mmermerkaya authored and Josh Crowther committed May 8, 2018
1 parent 785cc8b commit b351749
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
39 changes: 22 additions & 17 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
declare namespace firebase {
type NextFn<T> = (value: T) => void;
type ErrorFn<E = Error> = (error: E) => void;
type CompleteFn = () => void;

interface FirebaseError {
Expand All @@ -23,10 +25,10 @@ declare namespace firebase {
stack?: string;
}

interface Observer<V, E> {
complete(): any;
error(error: E): any;
next(value: V | null): any;
interface Observer<T, E = Error> {
next: NextFn<T>;
error: ErrorFn<E>;
complete: CompleteFn;
}

var SDK_VERSION: string;
Expand Down Expand Up @@ -215,14 +217,14 @@ declare namespace firebase.auth {
settings: firebase.auth.AuthSettings;
onAuthStateChanged(
nextOrObserver:
| firebase.Observer<any, any>
| firebase.Observer<any>
| ((a: firebase.User | null) => any),
error?: (a: firebase.auth.Error) => any,
completed?: firebase.Unsubscribe
): firebase.Unsubscribe;
onIdTokenChanged(
nextOrObserver:
| firebase.Observer<any, any>
| firebase.Observer<any>
| ((a: firebase.User | null) => any),
error?: (a: firebase.auth.Error) => any,
completed?: firebase.Unsubscribe
Expand Down Expand Up @@ -553,17 +555,23 @@ declare namespace firebase.messaging {
}

interface Messaging {
deleteToken(token: string): Promise<any> | null;
getToken(): Promise<any> | null;
deleteToken(token: string): Promise<boolean>;
getToken(): Promise<string | null>;
onMessage(
nextOrObserver: firebase.Observer<any, any> | ((a: Object) => any)
nextOrObserver: firebase.NextFn<any> | firebase.Observer<any>,
error?: firebase.ErrorFn,
completed?: firebase.CompleteFn
): firebase.Unsubscribe;
onTokenRefresh(
nextOrObserver: firebase.Observer<any, any> | ((a: Object) => any)
nextOrObserver: firebase.NextFn<any> | firebase.Observer<any>,
error?: firebase.ErrorFn,
completed?: firebase.CompleteFn
): firebase.Unsubscribe;
requestPermission(): Promise<any> | null;
setBackgroundMessageHandler(callback: (a: Object) => any): any;
useServiceWorker(registration: any): any;
requestPermission(): Promise<void>;
setBackgroundMessageHandler(
callback: (payload: any) => Promise<any> | void
): void;
useServiceWorker(registration: ServiceWorkerRegistration): void;
usePublicVapidKey(b64PublicKey: string): void;
}
}
Expand Down Expand Up @@ -662,10 +670,7 @@ declare namespace firebase.storage {
catch(onRejected: (a: Error) => any): Promise<any>;
on(
event: firebase.storage.TaskEvent,
nextOrObserver?:
| firebase.Observer<any, any>
| null
| ((a: Object) => any),
nextOrObserver?: firebase.Observer<any> | null | ((a: Object) => any),
error?: ((a: Error) => any) | null,
complete?: (firebase.Unsubscribe) | null
): Function;
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/util/node_persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ if (process.env.USE_MOCK_PERSISTENCE === 'YES') {
globalAny.window = Object.assign(globalAny.window || {}, {
indexedDB: globalAny.indexedDB
});
}
}
4 changes: 3 additions & 1 deletion packages/messaging-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class FirebaseMessaging {
completed?: CompleteFn
): Unsubscribe;
requestPermission(): Promise<void>;
setBackgroundMessageHandler(callback: (a: any) => Promise<void>): void;
setBackgroundMessageHandler(
callback: (payload: any) => Promise<any> | void
): void;
useServiceWorker(registration: ServiceWorkerRegistration): void;
usePublicVapidKey(b64PublicKey: string): void;
}
3 changes: 2 additions & 1 deletion packages/messaging/src/controllers/controller-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { IIDModel } from '../models/iid-model';
import { TokenDetailsModel } from '../models/token-details-model';
import { VapidDetailsModel } from '../models/vapid-details-model';

export type BgMessageHandler = (input: MessagePayload) => Promise<void>;
// tslint:disable-next-line no-any User can return any type of promise.
export type BgMessageHandler = (payload: MessagePayload) => Promise<any> | void;

const SENDER_ID_OPTION_NAME = 'messagingSenderId';
// Database cache should be invalidated once a week.
Expand Down

0 comments on commit b351749

Please sign in to comment.