代码之家  ›  专栏  ›  技术社区  ›  Yangshun Tay

如何在Deno中指定或覆盖TypeScript配置

  •  0
  • Yangshun Tay  · 技术社区  · 5 年前

    我刚开始一个新的Deno项目,但遇到了错误

    const users = [
      { name: 'Oby', age: 12 },
      { name: 'Heera', age: 32 },
    ];
    
    const loggedInUser = users.find((u) => u.name === 'Oby');
    console.log(loggedInUser.age);
    
    $ deno run hello.ts
    Compile file:///Users/yangshun/Downloads/deno-test/hello.ts
    error: TS2532 [ERROR]: Object is possibly 'undefined'.
    console.log(loggedInUser.age);
    

    这是由 "strictNullChecks": true 在TypeScript配置中。因此我想用我自己的 tsconfig.json (TypeScript配置)但我不确定如何进行。

    1 回复  |  直到 5 年前
        1
  •  2
  •   Yangshun Tay    5 年前
    1. 创建一个 tsconfig.json 文件
    {
      "compilerOptions": {
        "strictNullChecks": false
      }
    }
    
    1. 执行 deno run -c 配置参数。
    $ deno run -c tsconfig.json hello.ts
    Compile file:///Users/yangshun/Downloads/deno-test/hello.ts
    12
    
    推荐文章