react-native-maps-directions icon indicating copy to clipboard operation
react-native-maps-directions copied to clipboard

Wrong Type Inference on React Native project in TypeScript: `timePrecision` prop type is wrong

Open coawazie opened this issue 2 years ago • 0 comments

What is happening?

In a ReactNative typescript project, the type inferred for MapViewDirections prop named timePrecison is MapViewDirectionsPrecision which is defined thus;

type MapViewDirectionsPrecision =
    | "high"
    | "low";

The accepted values in Google Directions API are now and none, which match the type declaration for MapViewDirectionsTimePrecision

      | "now"
      | "none";

Hence, when timePrecision is set to high or low, it incorrectly infers it as the right type. However, at runtime, the following error is thrown

MapViewDirections Error: Error on GMAPS route request: Invalid request. Invalid 'departure_time' parameter.

When when timePrecision is set to now or none, it incorrectly infers it as the wrong type.

Expected

The type inferred for MapViewDirections prop named timePrecison should be MapViewDirectionsTimePrecision

      | "now"
      | "none";

Then the right type is manually edited in the types definition file, it infers the type for timePrecision correctly

Screenshots

Correct props labeled as incorrect

Screen Shot 2022-07-05 at 7 07 30 PM Screen Shot 2022-07-05 at 7 15 47 PM

Incorrect props labeled as correct

Screen Shot 2022-07-05 at 7 10 26 PM Screen Shot 2022-07-05 at 7 14 23 PM

When the right type is manually edited into the type definition

Screen Shot 2022-07-05 at 7 17 56 PM

coawazie avatar Jul 05 '22 23:07 coawazie