bramus / react-native-maps-directions

Directions Component for `react-native-maps`
MIT License
1.25k stars 198 forks source link

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

Open coawazie opened 2 years ago

coawazie commented 2 years ago

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