rowanwins / maplibregl-mapbox-request-transformer

Transform mapbox:// urls in MapboxGL Styles for use in MapLibreGL.
MIT License
26 stars 5 forks source link

`resourceType` can be `undefined`, leading to issues with forwarding `transformRequest` to `transformMapboxUrl` #7

Open JannikGM opened 1 year ago

JannikGM commented 1 year ago

Where we use this plugin, I've changed the code from the README to this:

      const transformRequest = (url: string, resourceType?: MapLibreResourceType) => {
        if (isMapboxURL(url)) {
          return transformMapboxUrl(url, resourceType ?? MapLibreResourceType.Unknown, accessToken)
        }
        return {url}
      }
  1. resourceType can be typed more strongly (ResourceType is exported by MapLibre). This should be fixed in the README.
  2. resourceType can be undefined because maplibre types it as ?: ResourceType (why?!), but transformMapboxUrl does not allow this. This should be fixed in this project (probably?).

Both of these problems were reported by the TypeScript compiler.

I'm also reporting this with maplibre, the original typing is here: https://github.com/maplibre/maplibre-gl-js/blame/main/src/util/request_manager.ts#L21