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

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

Open
nadralia opened this issue Feb 14, 2024 · 1 comment

Comments

@nadralia
Copy link

nadralia commented Feb 14, 2024

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);
        }
    };

@sheindel
Copy link
Contributor

sheindel commented Feb 14, 2024

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);

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

2 participants