Skip to content

Return type of listFiles method should take into account input parameters #114

@lorenzocestaro

Description

@lorenzocestaro

When calling listFiles the return type of the call is always FileObject | FolderObject regardless of the parameters passed to the listFiles call. This requires some extra type guards to process the response correctly in typescript, because some properties are exclusively present on files or folders.

For example:

// I would expect the type of resources here to be only FolderObject[]
const resources = await imagekit.listFiles({
  path: "/",
  type: "folder",
});

If I want to map over resources from above I will have to write some superfluous type guards to make sure TS knows we are working with Folders only. Yes, type-casting could be used, but I think this could be improved in the SDK types definitions

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions