typescript - Why use 'as' instead of type assertion (<>) in Typescript?
问题描述
I get the following warning from my IDE because I am using TSLint.
Fix: Type assertion using '<>' syntax is forbidden. Use the 'as' syntax instead.
I understand that I should write the following:
get myCtrl(): FormControl {
return this.formGroup.get('myCtrl') as FormControl;
}
instead of
get myCtrl(): FormControl {
return <FormControl> this.formGroup.get('myCtrl');
}
However, are there any main issues regarding the latter one (not only grammar ambiguity as suggested in this answer)? I have up to this point always used the latter notation, so I got a bit puzzled of why we have the 'as' keyword in typescript as opposed to just keep using type assertion.
解决方案
推荐阅读
- pytest - 气流 - DAG 完整性测试 - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) 没有这样的表:变量
- swift - 解析 Firebase 动态链接以重置密码 IOS
- c++ - 图中的 DFS 遍历
- python - 深度学习对 xy 空间坐标的时间序列进行分类 - python
- php - Centos 7 Nginx phpMyAdmin “无法识别的 Content-Security-Policy 指令‘referrer’。”
- wagtail - 如何将Wagtail editHandler中streamfield的每个字段的help_text内容传递到该字段的title属性?
- syntax - 带有中缀运算符名称的参数?
- node.js - 如何构建以将节点应用程序部署到 http 服务器
- spring-boot - GitHub Action Gradle buildBootImage
- api - 如何使用 HubSpot 的 CRM API 访问/检索通过搜索查询返回的“交易”对象的“所有者”对象或“所有者 ID”属性?