Skip to content

Commit

Permalink
Add methods for async stack traces to the types (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
Zen-cronic and sindresorhus authored Jun 29, 2024
1 parent 6bd2cc0 commit f294a7e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ export interface CallSite {
Returns `true` if this is a constructor call.
*/
isConstructor(): boolean;

/**
Returns `true` if this call is asynchronous (i.e. `await`, `Promise.all()`, or `Promise.any()`).
*/
isAsync(): boolean;

/**
Returns `true` if this is an asynchronous call to `Promise.all()`.
*/
isPromiseAll(): boolean;

/**
Returns the index of the promise element that was followed in `Promise.all()` or `Promise.any()` for async stack traces, or `null` if the `CallSite` is not an asynchronous `Promise.all()` or `Promise.any()` call.
*/
getPromiseIndex(): number | null;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ expectType<boolean>(callsite.isToplevel());
expectType<boolean>(callsite.isEval());
expectType<boolean>(callsite.isNative());
expectType<boolean>(callsite.isConstructor());
expectType<boolean>(callsite.isAsync());
expectType<boolean>(callsite.isPromiseAll());
expectType<number | null>(callsite.getPromiseIndex());
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ Returns an array of callsite objects with the following methods:
- `isEval`: Does this call take place in code defined by a call to `eval`?
- `isNative`: Is this call in native V8 code?
- `isConstructor`: Is this a constructor call?

- `isAsync()`: Returns `true` if this call is asynchronous (i.e. `await`, `Promise.all()`, or `Promise.any()`).
- `isPromiseAll()`: Returns `true` if this is an asynchronous call to `Promise.all()`.
- `getPromiseIndex()`: Returns the index of the promise element that was followed in `Promise.all()` or `Promise.any()` for async stack traces, or `null` if the `CallSite` is not an asynchronous `Promise.all()` or `Promise.any()` call.


---

<div align="center">
Expand Down

0 comments on commit f294a7e

Please sign in to comment.