Yangshun Tay
Yangshun Tay

Reputation: 53169

How to specify or override TypeScript config in Deno

I'm starting out on a new Deno project and ran into errors

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);

This is caused by "strictNullChecks": true in the TypeScript config. Hence I would like to use my own tsconfig.json (TypeScript configuration) but am not sure how to go about doing so.

Upvotes: 1

Views: 1058

Answers (1)

Yangshun Tay
Yangshun Tay

Reputation: 53169

  1. Create a tsconfig.json file.
{
  "compilerOptions": {
    "strictNullChecks": false
  }
}
  1. Execute the deno run with the -c configuration argument.
$ deno run -c tsconfig.json hello.ts
Compile file:///Users/yangshun/Downloads/deno-test/hello.ts
12

Upvotes: 2

Related Questions