got rid of forced casting

This commit is contained in:
Kristaps Fabians Geikins
2024-10-25 13:31:33 +03:00
parent 04400b1ee9
commit 716a108c7a
@@ -11,7 +11,8 @@ import {
DeleteObjectCommand,
CreateBucketCommand,
S3ServiceException,
S3ClientConfig
S3ClientConfig,
ServiceOutputTypes
} from '@aws-sdk/client-s3'
import { Upload, Options as UploadOptions } from '@aws-sdk/lib-storage'
import {
@@ -61,14 +62,12 @@ const getObjectStorage = () => ({
createBucket: createS3Bucket()
})
const sendCommand = async <CommandOutput>(
const sendCommand = async <CommandOutput extends ServiceOutputTypes>(
command: (Bucket: string) => Command<any, CommandOutput, any, any, any>
) => {
const { client, Bucket } = getObjectStorage()
try {
const ret = (await client.send(
command(Bucket) as Command<any, any, any, any, any>
)) as CommandOutput
const ret = await client.send(command(Bucket))
return ret
} catch (err) {
if (err instanceof S3ServiceException && get(err, 'Code') === 'NoSuchKey')