Type JSON conversions more thoroughly
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
The callback for [`ajax.getJSON`](https://github.com/mapbox/mapbox-gl-js/blob/b528524821deb2a22846a2cbe14a6691830e32c0/src/util/ajax.js#L59) is currently typed as `Callback`. `mixed` is the correct type -- an external API call could return any JSON structure. However, in consuming this result, downstream code often just bypasses flow typechecking by casting this `mixed` value to the expected type. ([Example](https://github.com/mapbox/mapbox-gl-js/blob/b528524821deb2a22846a2cbe14a6691830e32c0/src/style/image_sprite.js#L51).) It would be better to eliminate these casts, and get to the expected type via [refinement](https://flow.org/en/docs/lang/refinements/), which at the same time would serve as validation on the JSON response.
Contributor guide
Research direction
Start with the getJSON callback in src/util/ajax.js and the cast shown in src/style/image_sprite.js. Identify downstream consumers that cast the mixed JSON result, then use Flow refinements to establish the expected type and validate the response. Done means the relevant casts are removed and JSON consumers are typechecked without bypasses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100