API reference › @evolu/common › Types › isPromiseLike
function isPromiseLike<T>(value: Awaitable<T>): value is PromiseLike<T>;
Defined in: packages/common/src/Types.ts:256
Type guard to check if a value is a PromiseLike.
Use with Awaitable to conditionally await only when necessary,
avoiding microtask overhead for synchronous values.
Example
const validate = (id: string): Awaitable<boolean> => {
const cached = cache.get(id);
if (cached !== undefined) return cached; // Sync path
return fetchValidation(id); // Async path
};
const result = validate(id);
const isValid = isPromiseLike(result) ? await result : result;