最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting error TypeError: Promise.any is not a function - Stack Overflow

programmeradmin5浏览0评论

I am learning Promise.any from the following site. The IDE does not show any error, but while running using yarn mand , 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._pile (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

I am learning Promise.any from the following site. https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any The IDE does not show any error, but while running using yarn mand , 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._pile (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

Share Improve this question edited Jul 27, 2020 at 21:10 Deba asked Jul 27, 2020 at 21:07 DebaDeba 9895 gold badges10 silver badges25 bronze badges 12
  • 2 this feature is not yet available in the latest stable chrome. use chrome canary version and it will work fine – Andrei Commented Jul 27, 2020 at 21:10
  • Sir, I am writing it as standalone program, – Deba Commented Jul 27, 2020 at 21:12
  • 1 not sure about node, but your browser surely doesn't. It seems this exact feature is very new – Andrei Commented Jul 27, 2020 at 21:14
  • 3 developer.mozilla/en-US/docs/Web/JavaScript/Reference/… It's not supported by Node yet. – John Montgomery Commented Jul 27, 2020 at 21:18
  • 2 According to the MDN page - none. That's what you get for using brand new features. – Robin Zigmond Commented Jul 27, 2020 at 21:24
 |  Show 7 more ments

2 Answers 2

Reset to default 11

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.

Imho it's better to stick with whatever is supported in your current setup, and it seems like esnext.promise is not there yet, but:

I'm in a situation where I'm porting a sizeable live codebase away from Bluebird, and this npm module did it for me (I'm on node v12.12.0): https://www.npmjs./package/promise.any

发布评论

评论列表(0)

  1. 暂无评论