如何在 Typescript 项目中使用 Node 16 的计时器/promise?

Max*_*kov 6 node.js npm typescript

Node 16 版本中,我想使用新的计时器/承诺 API。我安装Node 16NVM切换到它:

$ nvm use       
Found '/Users/golergka/Projects/my-project/.nvmrc' with version <16>
Now using node v16.0.0 (npm v7.10.0)
Run Code Online (Sandbox Code Playgroud)

甚至还为我的添加了引擎package.json

"engines": { "node": ">=16" }
Run Code Online (Sandbox Code Playgroud)

我不确定是否需要安装 的版本16@types/node但我尝试了(没有成功):

npm install --save-dev @types/node@16
npm ERR! code ETARGET
npm ERR! notarget No matching version found for @types/node@16.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
Run Code Online (Sandbox Code Playgroud)

目前,我已经^14.14.41安装了。

最后,我尝试导入setTimeout我的Typescript文件:

$ nvm use       
Found '/Users/golergka/Projects/my-project/.nvmrc' with version <16>
Now using node v16.0.0 (npm v7.10.0)
Run Code Online (Sandbox Code Playgroud)

但出现错误:

Cannot find module 'timers/promises' or its corresponding type declarations.
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

The*_*rZZ 3

它已于 3 天前发布于@types/node。就跑npm install --save-dev @types/node@latest,或者yarn add --dev @types/node@latest。版本是0。