Currently, I am working on assigning a field within my interface to a function from an external library in the following manner:
import {
Accelerometer,
} from 'expo-sensors';
type SensorInterface = {
permChecker: () => Promise<PermissionResponse>;
};
type MonitorService = {
accelerometer: SensorInterface;
};
export const monitorService: MonitorService = {
accelerometer: {
permChecker: Accelerometer.requestPermissionsAsync,
},
};
However, when I access the global variable monitorService
, the permStatus remains undefined. My usage of it is as follows:
const sensors = ['accelerometer'];
for (const sensor of sensors) {
const service: SensorInterface = monitorService[sensor as keyof MonitorService];
console.log(`service = ${JSON.stringify(service)}`);
const perm = await service.permChecker();
}
Thank you for your assistance!
I anticipate that the function should be defined and callable.