Skip to content

Return Type for DroppedAssetFactory #61

@saqibmk

Description

@saqibmk

Issue tracker is ONLY used for reporting bugs.

Summary

Typescript error while fetching data object of a dropped asset

Expected Behavior

I should be able to infer or directly typecast the return type.

Current Behavior

An error is thrown while compiling Typescript.

Possible Solution

Change the return type from ResponseType to null | DataObjectType or something similar.

Steps to Reproduce

Generate a DroppedAssetFactory

const da= await new DroppedAssetFactory(topiaInstance).create(
    credentials.assetId,
    credentials.urlSlug,
    {
      credentials,
    },
  );

Fetch Data Object

const data = await settingsAsset.fetchDataObject();

The return type here is void | ResponseType

If I try to typecast

const currentDataObject = (await settingsAsset.fetchDataObject()) as DataObjectType; an error is thrown:

Conversion of type 'void | ResponseType' to type 'DataObjectType' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Property 'assets' is missing in type 'ResponseType' but required in type 'DataObjectType'.


Context All

Providing context helps us come up with a solution that is most useful in the real world.

If the return type can be typecasted, we could easily rely on code-completion, and won't have to do:

const currentDataObject = (await settingsAsset.fetchDataObject()) as unknown as DataObjectType;


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions