Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example does not work: MergeMap Errors #89

Open
TheOd1n opened this issue Sep 3, 2023 · 1 comment
Open

Example does not work: MergeMap Errors #89

TheOd1n opened this issue Sep 3, 2023 · 1 comment

Comments

@TheOd1n
Copy link

TheOd1n commented Sep 3, 2023

Example 2.b) generates the following error message when copied to the Angular project:

Argument of type 'OperatorFunction<BluetoothRemoteGATTService, void | BluetoothRemoteGATTCharacteristic>' is not assignable to parameter of type 'OperatorFunction<BluetoothRemoteGATTService, BluetoothRemoteGATTCharacteristic>'.
Type 'void | BluetoothRemoteGATTCharacteristic' is not assignable to type 'BluetoothRemoteGATTCharacteristic'.
Type 'void' is not assignable to type 'BluetoothRemoteGATTCharacteristic'.

@batchi92
Copy link

batchi92 commented Sep 4, 2023

There are several bugs in the library. The Promise.reject(...) parts in bluetooth.service.ts line 162, 255 and 264 must be returned. In the else branch of line 165 a Promise.reject(...) must also be returned. I use the following hot fix:

  private readonly fixMap = <T>(t: T | void) => {
    if (!t) {
      throw new Error();
    }
    return t;
  };

  private readonly device$ = this.bluetooth
    .discover$({
      optionalServices: [this.serviceUuid],
      filters: [{ services: [this.globalServiceUuid] }],
    })
    .pipe(
      // Hot fix for bug in bluetooth core
      map(this.fixMap),
      mergeMap(server =>
        this.bluetooth.getPrimaryService$(server, this.serviceUuid)
      ),
      mergeMap(service =>
        this.bluetooth.getCharacteristic$(service, this.characteristicUuid)
      ),
      // Hot fix for bug in bluetooth core
      map(this.fixMap)
    );

@manekinekko you should enable strict mode to avoid such mistakes. Best greetings :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants