【发布时间】:2020-10-15 16:17:04
【问题描述】:
我在 typescript (3.9.5) 中有以下内容:
const height: number = $(window).height();
这失败了:
TS2322: Type 'number | undefined' is not assignable to type 'number'.
我正在使用以下相关软件包:
"jquery": "^3.4.1",
"@types/jquery": "^3.5.0"
在打字稿中处理这个问题的正确方法是什么?
【问题讨论】:
-
我猜它是通用的,没有检查但也许你可以为 $
添加一个定义...或附加 as number
标签: jquery typescript typescript-typings