strict mode typescript checks fails from tsconfig.json

547 Views Asked by At

I have a simple typing error detected with cli flag --strict

$ ./node_modules/.bin/tsc --strict main.ts
main.ts:6:5 - error TS2322: Type 'null' is not assignable to type 'Person'.

6     return null;
      ~~~~~~~~~~~~

When I try to put the strict flag inside tsconfig.json it doesn't work:

$ cat tsconfig.json
{ "compilerOptions": { "strict": true } }
$ ./node_modules/.bin/tsc main.ts
$ # no typing errors found 

The actual source code is (probably) irrelevant, but for completeness reasons:

class Person {
  constructor(private lastName: string){}

  public getFriend(name: string): Person {
    if (name == "Someone") { return new Person("Mr."); }
    return null;
  }
}
1

There are 1 best solutions below

1
Dimava On

In tsconfig that's strictNullChecks