Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

react native library doesn't function as expected

$
0
0

I have a react-native-library that has my Healthkit queries. I install this library in my main app and call all the queries. The authorization part doesn't seem to work. I guess some issue in my library's TS files.

Healthkit query:

 @objc(requestAuthorization:read:resolve:withRejecter:) func requestAuthorization(toShare: NSDictionary, read: NSDictionary, resolve: @escaping RCTPromiseResolveBlock,reject: @escaping RCTPromiseRejectBlock) {                let share = sampleTypesFromDictionary(typeIdentifiers: toShare);                let toRead = objectTypesFromDictionary(typeIdentifiers: read);                    healthStore.requestAuthorization(toShare: share, read: toRead) { (success: Bool, error: Error?) in                        guard let err = error else {                            return resolve(success);                        }                        //handle error                    }          }

TS file (index)

export declare enum HKQuantityTypeIdentifier {    HeartRate = "HKQuantityTypeIdentifierHeartRate"  }  export type WritePermssions = {    [key in     HKQuantityTypeIdentifier]: boolean;  };  export type ReadPermssions = {    [key in    HKQuantityTypeIdentifier]: boolean;  };  type ReactNativeHealthkitTypeNative = {    requestAuthorization(      write: WritePermssions | {},      read: ReadPermssions | {}    ): Promise<boolean>;  };const requestAuthorization = (    read: (HKQuantityTypeIdentifier)[],    write: HKQuantityTypeIdentifier[] = []  ): Promise<boolean> => {    const readAuth = read.reduce((obj, cur) => {        return { ...obj, [cur]: true };      }, {});    const writeAuth = write.reduce((obj, cur) => {        return { ...obj, [cur]: true };      }, {});    return NativeModules.requestAuthorization(writeAuth, readAuth);  }; type authorizationMethod = (    read: (HKQuantityTypeIdentifier)[],    write?: HKQuantityTypeIdentifier[]  ) => Promise<boolean>; type ReactNativeHealthkit = {    requestAuthorization: authorizationMethod;  }  const MyHealthLibrary: ReactNativeHealthkit = {    requestAuthorization  }  export default MyHealthLibrary;

In the front-end my js file:

import MyHealthLibrary, { HKQuantityTypeIdentifier } from 'my-health-library'; await MyHealthLibrary.requestAuthorization([HKQuantityTypeIdentifier.HeartRate])

Expected result:

enter image description here

But i get this error. Where am i going wrong here???????

enter image description here


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>