node.js - 如何在 Typescript 项目中使用 Node 16 中的计时器/承诺?
问题描述
在Node 16 版本中,我想使用新的 timers/promises API 。我安装Node 16
并NVM
切换到它:
$ nvm use
Found '/Users/golergka/Projects/my-project/.nvmrc' with version <16>
Now using node v16.0.0 (npm v7.10.0)
甚至将引擎添加到我的package.json
:
"engines": { "node": ">=16" }
我不确定是否需要安装 的版本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.
目前,我已经^14.14.41
安装了。
最后,我尝试setTimeout
在我的Typescript
文件中导入:
import { setTimeout } from 'timers/promises'
但出现错误:
Cannot find module 'timers/promises' or its corresponding type declarations.
我怎样才能解决这个问题?
解决方案
它已于 3 天前在@types/node
. 只需运行npm install --save-dev @types/node@latest
,或yarn add --dev @types/node@latest
。版本为 0。
推荐阅读
- c# - Wrapping an iframe URL
- css - Graphviz 中的 CSS 样式表
- reactjs - React 中函数式组件和使用 useMemo() 创建组件有什么区别
- javascript - javascript matching a term that may or may not exist, but should be matching if exist
- java - My IntelliJ Project Creation isn't providing me with any structure
- amazon-web-services - AWS Route 53 - 公共子域无法公开访问?
- html - Why is my custom style not taken by the HTML page?
- c# - ASP NET Core Minimal API 总是返回 200 而不是指定的 204
- laravel - Laravel HasMany GroupBy Sum
- timeline - Can we change format of Notes showing in the Activity TimeLine?