Skip to content

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

Open
@nicbovee

Description

@nicbovee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions