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

saveMindfulSession requires startDate and endDate but HealthValueOptions marks these properties to optional. #295

Open
nicbovee opened this issue Feb 28, 2023 · 0 comments · May be fixed by #296
Labels
bug Something isn't working

Comments

@nicbovee
Copy link

Describe the bug
When you use the saveMindfulSession method, the options argument is typed as HealthValueOptions. This typing makes the value property required and the startTime and endTime properties optional.

To Reproduce
Steps to reproduce the behavior:

  1. Create a function that inits the AppleHealthKit with write permissions for MindfulSession.
import AppleHealthKit, {
  HealthValue,
  HealthKitPermissions,
  HealthInputOptions,
  HealthValueOptions,
  HealthUnit,
} from 'react-native-health'

/* Permission options */
const permissions = {
  permissions: {
    write: [AppleHealthKit.Constants.Permissions.MindfulSession],
  },
} as HealthKitPermissions

export function trackMindfulMinutes(
  startDate: string | undefined,
  endDate: string | undefined,
) {
  AppleHealthKit.initHealthKit(permissions, (error: string) => {
    /* Called after we receive a response from the system */

    if (error) {
      console.log('[ERROR] Cannot grant permissions!')
    }

    let options: HealthValueOptions = {
      startDate: startDate,
      endDate: endDate,
    }
    console.log(options)

    AppleHealthKit.saveMindfulSession(
      options,
      (err: Object, results: HealthValue) => {
        if (err) {
          console.error(err)
          return {
            err,
          }
        }
        console.log(results)
        return results
      },
    )
  })
}
  1. Notice the unsatisfied type error on options:
Property 'value' is missing in type '{ startDate: string | undefined; endDate: string | undefined; }' but required in type 'HealthValueOptions'.
  1. Add the value and remove the start and end date props.
  2. Run this method passing just a value.
  3. See the error:
{"message": "startDate and endDate are required in options"}

Expected behavior
I would expect the options type to align with the requirements of the underlying native module. If the values prop hasn't been implemented yet, it shouldn't be a required property.

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: iPhone 13 Simulator
  • OS: iOS16
@nicbovee nicbovee added the bug Something isn't working label Feb 28, 2023
@nicbovee nicbovee linked a pull request Feb 28, 2023 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant