@@ -12,12 +12,12 @@ import {
1212 throws ,
1313} from '../test-utils' ;
1414
15- function largerOrEqualThanZero ( x ) {
15+ function largerOrEqualThanZero ( x : number ) {
1616 return x >= 0 ;
1717}
1818
19- function largerOrEqualThanZeroInRandomTime ( x ) {
20- return new Promise ( ( resolve ) =>
19+ function largerOrEqualThanZeroInRandomTime ( x : number ) {
20+ return new Promise < boolean > ( ( resolve ) =>
2121 setTimeout ( ( ) => {
2222 resolve ( x >= 0 ) ;
2323 } , Math . random ( ) * 100 ) ,
@@ -26,7 +26,7 @@ function largerOrEqualThanZeroInRandomTime(x) {
2626
2727describe ( 'asyncEveryStrict()' , ( ) => {
2828 it ( 'example from README works as described' , async ( ) => {
29- const indexes = [ ] ;
29+ const indexes : number [ ] = [ ] ;
3030
3131 const largerThanZero = await asyncEveryStrict ( [ 1 , 2 , 3 ] , async ( el , index ) => {
3232 indexes . push ( index ) ;
@@ -150,4 +150,41 @@ describe('asyncEveryStrict()', () => {
150150
151151 await expect ( ( ) => asyncEveryStrict ( inputArr , mapper ) ) . rejects . toThrow ( 'Some error' ) ;
152152 } ) ;
153+
154+ it ( 'returns type boolean given function that returns type Promise<boolean>' , async ( ) => {
155+ // @ts -expect-no-error
156+ const result : boolean = await asyncEveryStrict ( inputArr , largerOrEqualThanZeroInRandomTime ) ;
157+
158+ expect ( typeof result ) . toBe ( 'boolean' ) ;
159+ } ) ;
160+
161+ it ( 'returns type true given function that returns type Promise<true>' , async ( ) => {
162+ async function trueInRandomTime ( ) {
163+ return new Promise < true > ( ( resolve ) =>
164+ setTimeout ( ( ) => {
165+ resolve ( true ) ;
166+ } , Math . random ( ) * 100 ) ,
167+ ) ;
168+ }
169+
170+ // @ts -expect-no-error
171+ const result : true = await asyncEveryStrict ( inputArr , trueInRandomTime ) ;
172+
173+ expect ( result ) . toBe ( true ) ;
174+ } ) ;
175+
176+ it ( 'returns type false given function that returns type Promise<false>' , async ( ) => {
177+ async function falseInRandomTime ( ) {
178+ return new Promise < false > ( ( resolve ) =>
179+ setTimeout ( ( ) => {
180+ resolve ( false ) ;
181+ } , Math . random ( ) * 100 ) ,
182+ ) ;
183+ }
184+
185+ // @ts -expect-no-error
186+ const result : false = await asyncEveryStrict ( inputArr , falseInRandomTime ) ;
187+
188+ expect ( result ) . toBe ( false ) ;
189+ } ) ;
153190} ) ;
0 commit comments