javascript - VsCode 在类型转换时没有给出语法错误
问题描述
interface TypeA {
prop1: string;
prop2: string;
}
const b = <TypeA> { prop1: 'str', prop3: 'str' };
console.log(b.prop1);
vscode 在这种情况下没有给出语法错误。我想要“prop2 is missing”错误
解决方案
将类型放在变量名上。然后你就有了你想要的。
interface TypeA {
prop1: string;
prop2: string;
}
const b: TypeA = { prop1: 'str', prop3: 'str' };
console.log(b.prop1);
推荐阅读
- excel - 使用合并单元格过滤工作表中的数据
- alibaba-cloud - aliyun cli SDK 产品容器注册 (CR) 错误
- javascript - 使用javascript处理文件打开
- ruby - 在 Sequel/Ruby 中映射嵌套模型对象?
- java - 有没有办法可以将多个表数据保存到 mysql
- javascript - Ag Grid 单击复选框调用函数
- python - 根据更复杂的条件删除 pandas 中的行
- c# - 如何使用 Microsoft 帐户创建本地 Windows 帐户?
- python - 根据入口/出口索引列表从单个数组中提取多个数组/列表,而不循环索引
- java - 如何在实时firebase数据库中将多种类型的用户重定向到他们各自的活动?