File tree Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1
- export function isThenable < T > ( src : T | Promise < T > ) : src is Promise < T > {
2
- return src && typeof src === "object" && typeof ( src as any ) . then === "function" ;
1
+ /**
2
+ * @internal
3
+ */
4
+ export function isThenable < T > ( value : T | Promise < T > ) : value is Promise < T > {
5
+ return value && typeof value === "object" && "then" in value && typeof value . then === "function" ;
3
6
}
Original file line number Diff line number Diff line change 1
1
export { type CompatibilityOptions } from "./compatibility-check" ;
2
2
export { computeHash } from "./compute-hash" ;
3
3
export { interpolate } from "./interpolate" ;
4
+ export { isThenable } from "./is-thenable" ;
4
5
export { requireUncached } from "./require-uncached" ;
5
6
export { ruleExists } from "./rule-exists" ;
Original file line number Diff line number Diff line change
1
+ import { isThenable } from "./is-thenable" ;
2
+
3
+ it ( "should return true if given a promise" , ( ) => {
4
+ expect . assertions ( 1 ) ;
5
+ const value = Promise . resolve ( "foo" ) ;
6
+ expect ( isThenable ( value ) ) . toBeTruthy ( ) ;
7
+ } ) ;
8
+
9
+ it ( "should return false if given a primitive value" , ( ) => {
10
+ expect . assertions ( 1 ) ;
11
+ const value = "foo" ;
12
+ expect ( isThenable ( value ) ) . toBeFalsy ( ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Test if value is a Promise (thenable).
3
+ *
4
+ * @internal
5
+ */
6
+ export function isThenable < T > ( value : T | Promise < T > ) : value is Promise < T > {
7
+ return value && typeof value === "object" && "then" in value && typeof value . then === "function" ;
8
+ }
You can’t perform that action at this time.
0 commit comments