Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error TypeError: Promise.any is not a function

I am learning Promise.any from the following site. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any The IDE does not show any error, but while running using yarn command , I am getting the following error.

E:\typescript-2020-1\promise-usages-1\lib\basics1\promise-any.service.js:18                                                
        Promise.any([                                                                                                      
                ^                                                                                                                                                                              
TypeError: Promise.any is not a function                                                                                   
    at PromiseAnyService.validateAll_Type1 (E:\typescript-2020-1\promise-usages-1\lib\basics1\promise-any.service.js:18:17)
    at Object.<anonymous> (E:\typescript-2020-1\promise-usages-1\lib\test.js:35:7)                                         
    at Module._compile (internal/modules/cjs/loader.js:1137:30)                                                            
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)                                              
    at Module.load (internal/modules/cjs/loader.js:985:32)                                                                 
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)                                                       
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)                                    
    at internal/main/run_main_module.js:17:47                                                                              
 ERROR  Command failed with exit code 1.      

                                                                         

I have written the simple code to test. Please help where I am doing wrong in a Typescript class.

const promise1 = Promise.reject(0);
const promise2 = new Promise((resolve) => setTimeout(resolve, 100, 'quick'));
const promise3 = new Promise((resolve) => setTimeout(resolve, 500, 'slow'));

const proms = [promise1, promise2, promise3];

Promise.any(proms).then((result) => console.log(result));

Currently I am using NodeJs 12 and Typescript 3.8.3

like image 466
Deba Avatar asked Jan 24 '23 20:01

Deba


1 Answers

The method Promise.any was supported in node.js 15.0.0, your node.js version is old, so you could update it and try again.

like image 143
Alisa Liu 666 Avatar answered Jan 27 '23 11:01

Alisa Liu 666