bramus / bramus/react-native-maps-directions

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

Open
#194 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.3k
Forks
210
PR merge metrics
No merged PRs in 30d

Description

### 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`
``` export type 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`
``` export type 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](https://user-images.githubusercontent.com/26738901/177431544-b1f53701-85e1-4887-84ef-08836f3d33a8.png)
![Screen Shot 2022-07-05 at 7 15 47 PM](https://user-images.githubusercontent.com/26738901/177432159-d6c07e00-3c1a-498a-b83d-e6f8a61c8a4b.png)

#### Incorrect props labeled as correct
![Screen Shot 2022-07-05 at 7 10 26 PM](https://user-images.githubusercontent.com/26738901/177431736-469f5717-589a-4611-b008-bcea962b13d6.png)
![Screen Shot 2022-07-05 at 7 14 23 PM](https://user-images.githubusercontent.com/26738901/177432051-cee6d71b-0f1d-4366-9082-b3eda7af5585.png)

#### When the right type is manually edited into the type definition
![Screen Shot 2022-07-05 at 7 17 56 PM](https://user-images.githubusercontent.com/26738901/177432315-41890617-f89b-4099-9299-16a5f142f957.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.