react-native-maps-directions
react-native-maps-directions copied to clipboard
Wrong Type Inference on React Native project in TypeScript: `timePrecision` prop type is wrong
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
Incorrect props labeled as correct