【发布时间】:2021-12-23 18:38:54
【问题描述】:
今天出现此错误时,我正在使用 Angular。我在Typescript error This condition will always return 'true' since the types have no overlap 上阅读了接受的答案,但我不知道它是什么意思。
模板:
<div class="container">
Paste your text here: <textarea #count width="150" height="150"></textarea><br>
<button class="btn btn-dark" (click)=check(count.value)>Count</button>
<br>
<p id="result"></p>
</div>
组件:
import { Component, OnInit } from '@angular/core';
// import { checkServerIdentity } from 'tls'; i don't exist!
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
check(text:string) {
var counts:string[];
counts = text.split(" ");
let resultid = document.getElementById("result");
if (counts === "" /* here error */) {
// where i left over
}
}
}
错误:
This condition will always return \'false\' since the types \'string\[\]\' and \'string\' have no overlap. ts(2367)
【问题讨论】:
-
counts是一个字符串数组,""是一个字符串,所以根本没有必要比较它们。他们永远不会平等。只需写if (false) {或完全删除该块。
标签: angular typescript