条件始终为真,因为类型“string”和“null”没有重叠

问题描述 投票:0回答:0

这个警告是什么意思?

条件始终为真,因为类型“string”和“null”没有重叠

有问题的代码:

function foo() {
    let input: string | null = prompt("test");
    if (input !== null) {
        console.log("not aborted");
    }
}

这似乎只发生在

<script setup lang="ts">
文件的
.vue
部分,而不是在独立的
.ts
文件中。

我的

tsconfig.json
strict
isolatedModules
设置为
true
.

typescript phpstorm
© www.soinside.com 2019 - 2024. All rights reserved.