I've created a generic "fetcher" function that is designed to handle different types of entities. However, I'm encountering an issue where TypeScript is inferring the return type based on all possible conditions within the function.
Is there a way to explicitly specify the return type in order to avoid this ambiguity?
(initialNotes and initialTags represent two distinct array types)
async function fetcherFunc(entity) {
await new Promise((resolve) => setTimeout(resolve, 2000));
if (entity === 'notes') {
return initialNotes;
} else if (entity === 'tags') {
return initialTags;
}
}