strict mode typescript checks fails from tsconfig.json [duplicate]
Asked Answered
D

1

1

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;
  }
}
Disorient answered 27/11, 2022 at 10:51 Comment(0)
U
0

In tsconfig that's strictNullChecks

Unasked answered 27/11, 2022 at 11:20 Comment(1)
"strict": true implicitly enables strictNullChecks; specifying strictNullChecks in the tsconfig also does not aid this error. – Lattermost

© 2022 - 2024 β€” McMap. All rights reserved.