jsconfig非常实用的JS代码检查选项

平常大型工程项目,都会使用ts编码,js只是作为偶尔测试的代码。

但还是有时候,比如刷力扣、验证一些东西,就想简单的用一下js,不想搞那么复杂,单硬写js,又容易搞出来一堆简单的笔误。这时候jsconfig就派上用场了。

下面是非常实用的jsconfig

{
  "compilerOptions": {
    "noImplicitReturns": true,
    "checkJs": true
  }
}

比方说,临时写了一段代码:

var msg = "aaa";

msg = 123;


function test(name) {
    if (name.length > 3) {
        return "large";
    }
    if(name.length > 1){
        return "not empty";
    }

    if(name == true){
        return "123";
    }

    if(name === '123'){
        return [];
    }
    // missing return 
}

test('aaa');

上面这段代码可以说有好几处错误,如果应用了jsconfig,就能提前知道,不用靠调试去发现错误

错误1:

 

 

赋值未考虑类型

错误2:

 

posted @ 2022-09-17 11:34  内心澎湃的水晶侠  阅读(453)  评论(0编辑  收藏  举报