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

How to specify or override TypeScript config in Deno

我正在开始一个新的 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);

这是由 TypeScript 配置中的 "strictNullChecks": true 引起的。因此,我想使用我自己的 tsconfig.json(TypeScript 配置),但我不确定如何去做。

  1. 创建一个 tsconfig.json 文件。
{
  "compilerOptions": {
    "strictNullChecks": false
  }
}
  1. 使用 -c 配置参数执行 deno run
$ deno run -c tsconfig.json hello.ts
Compile file:///Users/yangshun/Downloads/deno-test/hello.ts
12