Skip to content

getChanges returns MassResult but types define Mass #246

@SatoshiKawabata

Description

@SatoshiKawabata

Describe the bug
Hi, I think there is a type mismatch in getChanges return values.

getChanges returns upsertionChanges[].record as HealthConnectRecord:
https://github.com/matinzd/react-native-health-connect/blob/main/src/types/changes.types.ts#L10

For WeightRecord, the type uses Mass:
https://github.com/matinzd/react-native-health-connect/blob/main/src/types/records.types.ts#L169

export interface Mass {
  value: number;
  unit:
    | 'grams'
    | 'kilograms'
    | 'milligrams'
    | 'micrograms'
    | 'ounces'
    | 'pounds';
}

However, the actual runtime value is MassResult, not Mass:

export interface MassResult {
inGrams: number;
inKilograms: number;
inMilligrams: number;
inMicrograms: number;
inOunces: number;
inPounds: number;
}

Example returned value from getChanges:

{
  "recordType": "Weight",
  "weight": {
    "inGrams": 75000,
    "inKilograms": 75,
    "inMilligrams": 75000000,
    "inMicrograms": 75000000000,
    "inOunces": 2645.5474378402178,
    "inPounds": 165.3466966386582
  }
}

Is this behavior intentional?

If so, should the types for getChanges use MassResult instead of Mass, or should the returned value be normalized to Mass?

To Reproduce
using getChanges API.

Expected behavior
I expect to use MassResult type.

Screenshots
no screenshot

Environment:

  • Health Connect Version: 3.5.0
  • React Native Version: 0.79.5
  • New architecture enabled: Yes
  • Using Expo: Prebuild(Dev Client)
  • Android API Level: API 35

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions