Checks if a promise result is fulfilled. Can be used as a type guard to narrow the type of the result to PromiseFulfilledResult.
PromiseFulfilledResult
const fulfilled = new Promise((resolve) => setTimeout(() => resolve('done'), 1000));const result = await settled(fulfilled);console.log(isFulfilled(result)); // trueconst results = await Promise.allSettled([ Promise.resolve('done'), Promise.reject(new Error('fail')),]);console.log(results.filter(isFulfilled)); // [{ status: 'fulfilled', value: 'done' }]console.log(results.filter(isRejected)); // [{ status: 'rejected', reason: Error('fail') }] Copy
const fulfilled = new Promise((resolve) => setTimeout(() => resolve('done'), 1000));const result = await settled(fulfilled);console.log(isFulfilled(result)); // trueconst results = await Promise.allSettled([ Promise.resolve('done'), Promise.reject(new Error('fail')),]);console.log(results.filter(isFulfilled)); // [{ status: 'fulfilled', value: 'done' }]console.log(results.filter(isRejected)); // [{ status: 'rejected', reason: Error('fail') }]
Checks if a promise result is fulfilled. Can be used as a type guard to narrow the type of the result to
PromiseFulfilledResult
.