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

replacing enum - better solution needed

$
0
0

I have an app that uses React Native' Native Module.
Currently the logic is that the Data type will be obtained from my enum as shown below

export declare enum HKQuantityTypeIdentifier {    HeartRate = "HKQuantityTypeIdentifierHeartRate"  }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 NativeModule.requestAuthorization(writeAuth, readAuth);  };  const MyHealthLibrary: ReactNativeHealthkit = {    requestAuthorization  }  export default MyHealthLibrary;

Front-end call:

await MyHealthLibrary.requestAuthorization([HKQuantityTypeIdentifier.HeartRate]); 

This will give my expected result

enter image description here

Now i do not want to call the function from my front-end with the entire type "HKQuantityTypeIdentifier.HeartRate" instead i just want to call it like "HeartRate". Something like below:

await MyHealthLibrary.requestAuthorization(["HeartRate"]); 

How do i achieve this??? Any help would be great!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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