In my current project, I am working on implementing a function that will always return a fulfilled promise of the same "type" that is passed to it as a parameter.
This means that if I call the function with a boolean parameter, it should return a fulfilled Promise with a boolean value. The same goes for any other data type such as strings, numbers, etc.
Here's what I've attempted so far:
const createFulfilledPromise = <T>(val: T): Promise<T> => {
return Promise.resolve(val);
};
I'm not certain if this is the most effective way to achieve this functionality, and I have encountered issues when trying to get a Promise<void>.
Any suggestions or advice on how to improve this implementation would be greatly appreciated.