Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chinomnsoawazie opened this issue Jul 5, 2022 · 0 comments

Comments

@chinomnsoawazie
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant