我想更好地理解TS中的const assertions
考虑下图中的数组allDeviceTypes
,当我将鼠标悬停在变量名称VSCode上时,返回类型为string[]
但是,如果我使用const断言来缩小类型我看到了所需的缩小类型,但遇到了TSLint错误:
This assertion is unnecessary since it does not change the type of the expression. (no-unnecessary-type-assertion)tslint(1)
那是什么?表达式的类型是否相同或VSCode 1.40.0
+ TSlint 5.11.0
在工具提示中显示的类型不正确?
我有时也发现TS皮棉也有故障,快速搜索发现其他人也对此规则有疑问。
还有其他值得考虑的问题是TS lint即将被弃用,请参阅维护者的这篇文章:https://link.medium.com/T2BsQB3500。
[您可能考虑切换到ES皮棉,或者只是禁用该行上的规则。