I have some fairly dense type definitions for a chainable, promiselike/thenable object in TS.
My issue is that depending on the chained methods my then method should return a single or array or the final promise result, but even though I conditionally type it based on a variable called "many" passed though the internal methods, the results allways comes as a union of Promise<Result | Result[]> instead of the Promise<Result> or Promise<Result[]>.
Some help would be greately appreciated!
I do realize I might be leaving out some context, please feel free to answer or DM me if you need some extra information.
Here are the relevant files. If necessary I will upload my current package so you can play with it, since from the shared scripts you will not be able to test it locally.
(These scripts are not complete)
Files:
- The type definition file: https://gist.github.com/Adise0/bf5571dc71395838619cf7c724990317
- The class that generates this return object: https://gist.github.com/Adise0/a9d59e8f6e2a8d223cd285ee86bb52cc
- The class that calls the generation of the object: https://gist.github.com/Adise0/4f4fd773af25e3c1a77a269fff357ab0
As you can see I expect that, when calling the find method, the result should be an array of the SQLResult class, and when calling findById or findByPrimaryKey the result should be a single object.
In code this is working as expected, I do get my single/array results according to the designed implementation. TS however does not want to colaborate.