首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >typescript不理解松散相等和严格相等吗?

typescript不理解松散相等和严格相等吗?
EN

Stack Overflow用户
提问于 2021-09-16 18:55:18
回答 1查看 57关注 0票数 3

我收到的错误:

此条件将始终返回'true‘,因为类型'string’和'number‘没有重叠。

代码:

代码语言:javascript
运行
复制
if (this.$route.params.groupId != this.group.id) {
      more code here
 }

'1‘!= 1(将返回false)

“%1”!== %1(将返回true)

它不会总是返回true

EN

回答 1

Stack Overflow用户

发布于 2021-09-17 04:40:53

我认为您澄清了为什么typescript显示错误(来自typescript显示错误消息) https://github.com/microsoft/TypeScript/issues/26592

在我看来,我们可以确定变量的类型,以便正确地进行比较

代码语言:javascript
运行
复制
use `===` or `!==` to compare value
代码语言:javascript
运行
复制
Determine of type variable
const routeGroupId: string = this.$route.params.groupId;
const currentGroupId: string = this.group.id;
if(routeGroupId != currentGroupId)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69213748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档