Skip to content

Commit f294a7e

Browse files
Zen-cronicsindresorhus
andauthoredJun 29, 2024··
Add methods for async stack traces to the types (#22)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 6bd2cc0 commit f294a7e

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
 

‎index.d.ts

+15
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ export interface CallSite {
6565
Returns `true` if this is a constructor call.
6666
*/
6767
isConstructor(): boolean;
68+
69+
/**
70+
Returns `true` if this call is asynchronous (i.e. `await`, `Promise.all()`, or `Promise.any()`).
71+
*/
72+
isAsync(): boolean;
73+
74+
/**
75+
Returns `true` if this is an asynchronous call to `Promise.all()`.
76+
*/
77+
isPromiseAll(): boolean;
78+
79+
/**
80+
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.
81+
*/
82+
getPromiseIndex(): number | null;
6883
}
6984

7085
/**

‎index.test-d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ expectType<boolean>(callsite.isToplevel());
1616
expectType<boolean>(callsite.isEval());
1717
expectType<boolean>(callsite.isNative());
1818
expectType<boolean>(callsite.isConstructor());
19+
expectType<boolean>(callsite.isAsync());
20+
expectType<boolean>(callsite.isPromiseAll());
21+
expectType<number | null>(callsite.getPromiseIndex());

‎readme.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ Returns an array of callsite objects with the following methods:
3838
- `isEval`: Does this call take place in code defined by a call to `eval`?
3939
- `isNative`: Is this call in native V8 code?
4040
- `isConstructor`: Is this a constructor call?
41-
41+
- `isAsync()`: Returns `true` if this call is asynchronous (i.e. `await`, `Promise.all()`, or `Promise.any()`).
42+
- `isPromiseAll()`: Returns `true` if this is an asynchronous call to `Promise.all()`.
43+
- `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.
44+
45+
4246
---
4347

4448
<div align="center">

0 commit comments

Comments
 (0)
Please sign in to comment.