这是我在德诺运行的打字码。
import { assert } from "https://deno.land/std/testing/asserts.ts"
interface Tree{
size:number
}
let tree: Tree= {
size: 1
}
let f1 = (tree: Tree)=>{
tree.size--
}
function main(){
assert(tree.size === 1)
f1(tree);
assert(tree.size === 0);
}当我运行它时,它在第20行编译时给出了这个错误:
error: TS2367 [ERROR]: This condition will always return 'false' since the types '1' and '0' have no overlap.
assert(tree.size === 0);这是有效的断言,但是IDE和类型记录编译器都会对此抱怨。你怎么解决这个问题?
https://stackoverflow.com/questions/62037635
复制相似问题