Skip to content

Commit 3f2baef

Browse files
committed
fix(typescript): use correct ts version and fix promise types
Angular's compiler CLI requires typescript@^1.9.0-dev. The built-in Promise typings for that version of TS don't play well with Firebase Promise when using Promise.resolve, so the firebase_sdk_auth_backend has a function that will cast the promises as the correct type.
1 parent 0dde8ae commit 3f2baef

5 files changed

+21
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"traceur": "0.0.96",
7070
"tsd": "^0.6.5",
7171
"typedoc": "github:jeffbcross/typedoc",
72-
"typescript": "next",
72+
"typescript": "^2.0.2",
7373
"typings": "^1.3.2",
7474
"zone.js": "^0.6.21"
7575
},

src/auth/firebase_sdk_auth_backend.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class FirebaseSdkAuthBackend extends AuthBackend {
3434
}
3535

3636
createUser(creds: EmailPasswordCredentials): Promise<FirebaseAuthState> {
37-
return Promise.resolve(this._fbAuth.createUserWithEmailAndPassword(creds.email, creds.password))
37+
return castPromise<firebase.User>(this._fbAuth.createUserWithEmailAndPassword(creds.email, creds.password))
3838
.then((user: firebase.User) => authDataToAuthState(user));
3939
}
4040

@@ -64,17 +64,17 @@ export class FirebaseSdkAuthBackend extends AuthBackend {
6464
}
6565

6666
authWithCustomToken(token: string): Promise<FirebaseAuthState> {
67-
return Promise.resolve(this._fbAuth.signInWithCustomToken(token))
67+
return castPromise<firebase.User>((this._fbAuth.signInWithCustomToken(token)))
6868
.then((user: firebase.User) => authDataToAuthState(user));
6969
}
7070

7171
authAnonymously(): Promise<FirebaseAuthState> {
72-
return Promise.resolve(this._fbAuth.signInAnonymously())
72+
return castPromise<firebase.User>(this._fbAuth.signInAnonymously())
7373
.then((user: firebase.User) => authDataToAuthState(user));
7474
}
7575

7676
authWithPassword(creds: EmailPasswordCredentials): Promise<FirebaseAuthState> {
77-
return Promise.resolve(this._fbAuth.signInWithEmailAndPassword(creds.email, creds.password))
77+
return castPromise<firebase.User>(this._fbAuth.signInWithEmailAndPassword(creds.email, creds.password))
7878
.then((user: firebase.User) => authDataToAuthState(user));
7979
}
8080

@@ -83,7 +83,7 @@ export class FirebaseSdkAuthBackend extends AuthBackend {
8383
if (options.scope) {
8484
options.scope.forEach(scope => providerFromFirebase.addScope(scope));
8585
}
86-
return Promise.resolve(this._fbAuth.signInWithPopup(providerFromFirebase));
86+
return castPromise<firebase.auth.UserCredential>(this._fbAuth.signInWithPopup(providerFromFirebase));
8787
}
8888

8989
/**
@@ -92,16 +92,16 @@ export class FirebaseSdkAuthBackend extends AuthBackend {
9292
* You should subscribe to the FirebaseAuth object to listen succesful login
9393
*/
9494
authWithOAuthRedirect(provider: AuthProviders, options?: any): Promise<void> {
95-
return Promise.resolve(this._fbAuth.signInWithRedirect(this._enumToAuthProvider(provider)));
95+
return castPromise<void>(this._fbAuth.signInWithRedirect(this._enumToAuthProvider(provider)));
9696
}
9797

9898
authWithOAuthToken(credential: firebase.auth.AuthCredential): Promise<FirebaseAuthState> {
99-
return Promise.resolve(this._fbAuth.signInWithCredential(credential))
99+
return castPromise<firebase.User>(this._fbAuth.signInWithCredential(credential))
100100
.then((user: firebase.User) => authDataToAuthState(user));
101101
}
102102

103103
getRedirectResult(): Observable<firebase.auth.UserCredential> {
104-
return Observable.fromPromise(Promise.resolve(this._fbAuth.getRedirectResult()));
104+
return Observable.fromPromise(castPromise<firebase.auth.UserCredential>(this._fbAuth.getRedirectResult()));
105105
}
106106

107107
private _enumToAuthProvider(providerId: AuthProviders): any {
@@ -119,3 +119,8 @@ export class FirebaseSdkAuthBackend extends AuthBackend {
119119
}
120120
}
121121
}
122+
123+
// Cast Firebase promises as Zone-patched Promises
124+
function castPromise<T>(promiseLike: PromiseLike<T>): Promise<T> {
125+
return Promise.resolve(promiseLike) as Promise<T>;
126+
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"node_modules/zone.js/dist/zone.js.d.ts"
3434
],
3535
"angularCompilerOptions": {
36-
"skipTemplateCodegen": true
36+
"skipTemplateCodegen": true,
37+
"strictMetadataEmit": true
3738
}
3839
}

tsconfig.publish.es5.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"node_modules/zone.js/dist/zone.js.d.ts"
2525
],
2626
"angularCompilerOptions": {
27-
"skipTemplateCodegen": true
27+
"skipTemplateCodegen": true,
28+
"strictMetadataEmit": true
2829
}
2930
}

tsconfig.publish.es6.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"es2015",
1616
"dom"
1717
],
18+
"skipLibCheck": true,
1819
"moduleResolution": "node"
1920
},
2021
"files": [
@@ -25,6 +26,7 @@
2526
"node_modules/zone.js/dist/zone.js.d.ts"
2627
],
2728
"angularCompilerOptions": {
28-
"skipTemplateCodegen": true
29+
"skipTemplateCodegen": true,
30+
"strictMetadataEmit": true
2931
}
3032
}

0 commit comments

Comments
 (0)