Closed
Description
TypeScript Version:
1.8.10
Code
Failure:
this.loginService.loginUser(user, pass)
.subscribe(
payload => {
this.storageService.put('accesstoken', payload.token);
this.storageService.put('guid', payload.guid);
return this.loginService.fetchUserName(payload);
},
error => this.handleError(error)
);
Working:
const login: Observable<any> = this.loginService.loginUser(user, pass);
login.subscribe(
payload => {
this.storageService.put('accesstoken', payload.token);
this.storageService.put('guid', payload.guid);
return this.loginService.fetchUserName(payload);
},
error => this.handleError(error)
);
Definition for loginUser
:
public loginUser(userName: string, password: string): Observable<LoginResponse> | Observable<Error>
Expected behavior:
No errors
Actual behavior:
TS2349: Cannot invoke an expression whose type lacks a call signature
.
Notes
It comes from the |
operator in the loginUser
function. If I switch to a "determinist" type by putting Observable<any>
, typescript is some way "sure" (sorry for the term) of having an observable and it accepts the subscribe
call.