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
What is happening?
In a ReactNative typescript project, the type inferred for
MapViewDirections
prop namedtimePrecison
isMapViewDirectionsPrecision
which is defined thus;The accepted values in Google Directions API are
now
andnone
, which match the type declaration forMapViewDirectionsTimePrecision
Hence, when
timePrecision
is set tohigh
orlow
, it incorrectly infers it as the right type. However, at runtime, the following error is thrownWhen when
timePrecision
is set tonow
ornone
, it incorrectly infers it as the wrong type.Expected
The type inferred for
MapViewDirections
prop namedtimePrecison
should beMapViewDirectionsTimePrecision
Then the right type is manually edited in the types definition file, it infers the type for
timePrecision
correctlyScreenshots
Correct props labeled as incorrect
Incorrect props labeled as correct
When the right type is manually edited into the type definition