mapbox/shp-write

Argument of type 'string | ArrayBuffer | Blob | number[] | Uint8Array | Buffer | ReadableStream' is not assignable to parameter of type 'Blob | MediaSource'.

Opened this issue · 1 comments

I keep getting this typescript issue here below on this line const url = URL.createObjectURL(blob);

Argument of type 'string | ArrayBuffer | Blob | number[] | Uint8Array | Buffer | ReadableStream' is not assignable to parameter of type 'Blob | MediaSource'.
Type 'string' is not assignable to type 'Blob | MediaSource'.ts(2345)
const blob: string | Blob | number[] | Uint8Array | ArrayBuffer | Buffer | ReadableStream

    const convertToShapefileAndDownload = async (geoJson) => {
        try {
            if (!geoJson || typeof geoJson !== 'object') {
                throw new Error('Invalid GeoJSON data');
            }

            const options: any = { 
                folder: 'plots',
                types: {
                    point: 'points',
                    polygon: 'polygons',
                    polyline: 'lines',
                },
                compression: 'STORE' as any,
                outputType: 'blob',
            };

            const blob = await shpwrite.zip(geoJson, options);
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.download = 'plots_shapefile.zip';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            URL.revokeObjectURL(url);
        } catch (error) {
            //handleNotification(error, 'error');
            console.error('Error converting to Shapefile:', error.message);
        }
    };

Because of the way we're doing type inference in our typescript definition files, you need to provide the template argument for the type as well. Try changing this

const blob = await shpwrite.zip(geoJson, options)

to this

const blob = await shpwrite.zip<"blob">(geoJson, options);