Skip to content

Non-determinist signature results in TS2349 #9371

Closed
@gjuchault

Description

@gjuchault

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions