React-mapbox-gl: Type RequestTransformFunction should be RequestTransformFunction

Created on 7 Dec 2018  路  9Comments  路  Source: alex3165/react-mapbox-gl

While building my project, I noticed that the RequestTransformFunction type is incorrectly named versus @types/mapbox-gl. See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/c6f73c8050c16ceb3a9ac23df466361e9e22a4a1/types/mapbox-gl/index.d.ts

The error message when I compile with TypeScript:

/node_modules/react-mapbox-gl/lib/map.d.ts
(82,13): Subsequent property declarations must have the same type.  Property 'transformRequest' must be of type 'TransformRequestFunction | undefined', but here has type 'RequestTransformFunction | undefined'.

Most helpful comment

The types seem to be all over the place. Having massive problems.

First after installing @types/supercluster you get "@types/supercluster" has no exported member 'Supercluster' so to fix that set version to @types/[email protected].

Then have this problem which I solved by basically changing the type name from RequestTransformFunction to TransformRequestFunction in map.d.ts.

No idea if this is an ideal fix or what problems I will run into - but it compiles.

EDIT

map.d.ts

I have deleted these lines :

export declare type RequestTransformFunction = (url: string, resourceType: any) => any;
//
//
declare global {
    namespace mapboxgl {
        interface MapboxOptions {
            failIfMajorPerformanceCaveat?: boolean;
            transformRequest?: RequestTransformFunction;
        }
    }
}

and then replaced

export interface FactoryParameters {
    accessToken: string;
    apiUrl?: string;
    minZoom?: number;
    maxZoom?: number;
    hash?: boolean;
    preserveDrawingBuffer?: boolean;
    scrollZoom?: boolean;
    interactive?: boolean;
    dragRotate?: boolean;
    attributionControl?: boolean;
    customAttribution?: string | string[];
    logoPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
    renderWorldCopies?: boolean;
    trackResize?: boolean;
    touchZoomRotate?: boolean;
    doubleClickZoom?: boolean;
    keyboard?: boolean;
    dragPan?: boolean;
    boxZoom?: boolean;
    refreshExpiredTiles?: boolean;
    failIfMajorPerformanceCaveat?: boolean;
    bearingSnap?: number;
    injectCSS?: boolean;
    transformRequest?: MapboxGl.TransformRequestFunction; // use the type exposed from Mapbox types
}

All 9 comments

Is there a fix for this?

Would also be interested in a fix for this, seems like a fairly serious problem (in essence the library is not useable).

Any updates? :-)

The types seem to be all over the place. Having massive problems.

First after installing @types/supercluster you get "@types/supercluster" has no exported member 'Supercluster' so to fix that set version to @types/[email protected].

Then have this problem which I solved by basically changing the type name from RequestTransformFunction to TransformRequestFunction in map.d.ts.

No idea if this is an ideal fix or what problems I will run into - but it compiles.

EDIT

map.d.ts

I have deleted these lines :

export declare type RequestTransformFunction = (url: string, resourceType: any) => any;
//
//
declare global {
    namespace mapboxgl {
        interface MapboxOptions {
            failIfMajorPerformanceCaveat?: boolean;
            transformRequest?: RequestTransformFunction;
        }
    }
}

and then replaced

export interface FactoryParameters {
    accessToken: string;
    apiUrl?: string;
    minZoom?: number;
    maxZoom?: number;
    hash?: boolean;
    preserveDrawingBuffer?: boolean;
    scrollZoom?: boolean;
    interactive?: boolean;
    dragRotate?: boolean;
    attributionControl?: boolean;
    customAttribution?: string | string[];
    logoPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
    renderWorldCopies?: boolean;
    trackResize?: boolean;
    touchZoomRotate?: boolean;
    doubleClickZoom?: boolean;
    keyboard?: boolean;
    dragPan?: boolean;
    boxZoom?: boolean;
    refreshExpiredTiles?: boolean;
    failIfMajorPerformanceCaveat?: boolean;
    bearingSnap?: number;
    injectCSS?: boolean;
    transformRequest?: MapboxGl.TransformRequestFunction; // use the type exposed from Mapbox types
}

The only workaround I've found is to downgrade to TypeScript 3.1 or earlier.

I've asked about this on Stack Overflow: https://stackoverflow.com/questions/55068080/how-can-i-work-around-a-bug-in-a-published-type-declaration-file

@danvk I鈥檝e personally just forked it and fixed the types. More than happy to submit a PR

@amwill04 @pducks32 beat you to it: https://github.com/alex3165/react-mapbox-gl/pull/672

@danvk ha, fair play. Makes my life a hell of a lot easier.

Fix was released in v4.2.4

Was this page helpful?
0 / 5 - 0 ratings