javascript - 您如何理解 WebStorm 的功能接口?
问题描述
我无法理解某些功能及其接口。IE:
ReadonlyArray<unknown>.map(
callbackfn: (value: unknown, index: number, array: unknown[]) => unknown,
thisArg?: any): unknown[]
.map()
当我将鼠标悬停在一个函数上时,这就是 WebStorm 显示的内容。我知道.map()
将指定的回调函数作为参数,但是=> unknown
, 和thisArg?: any
代表什么?
同样,当我将鼠标悬停在一个forEach()
函数上时,弹出窗口如下所示:
ReadonlyArray<unknown>.forEach(
callbackfn: (value: unknown, index: number, array: unknown[]) => void,
thisArg?: any): void
forEach 也接受一个回调函数作为参数,但是=> void, thisArg?: any): void
代表什么呢?
解决方案
// the `.map` function is member of the generic type ReadonlyArray<unknown>. Where unknown is the type of the elements of the array
ReadonlyArray<unknown>.map(
// first argument is a callback function. The first argument of the callback is value, of type unknown, the second is index of type number, and so on
callbackfn: (value: unknown, index: number, array: unknown[])
// this parts means that the callback should return a value of type unknown
=> unknown,
// .map takes a second arguments called thisArg of any type. The ? means that the argument is optional
thisArg?: any)
// .map returns an array of type unknown
: unknown[]
该类型是未知的,因为它取决于所.map
应用的数组中存在的元素的类型。如果是对象数组,则未知类型为object
同样,forEach
接受第一个参数,它是一个回调。但是回调什么也不返回,因此你有=> void
.
推荐阅读
- java - android xml布局的意外结果
- azure-devops - 保留管道发布的 Nuget 包
- postgresql - PostgreSQL 查询经过的时间间隔
- c++ - VsCode 的错误曲线是怎么回事?
- laravel - 是否可以在 laravel 的单元测试中传递令牌来检查端点?传递令牌为空但检测到用户
- python - 在分布式工作人员中执行 Dask Graph
- firebase - 这个流是否像我想象的那样工作?
- google-app-engine - 使用 Cloud Domains 注册域
- python - 在同一构建目录中安装期间重复构建 Pip?
- r - 为什么 dev.new() 会打开 RStudioGD- 和 png 设备?