Return type of `listFiles` method should take into account input parameters
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
We can update it to show union of both and make all fields optional. Would that be better?
We decided not to merge the two fields into a union in order to maintain type safety. The core issue lies in the underlying API response, which needs improvement. We have already noted this for the V2 version.
If you have more ideas, you are welcome to add comments on this discussion - https://github.com/imagekit-developer/sdk-generation/discussions/3