Questions tagged [strictnullchecks]

--strictNullChecks (cli) or strictNullChecks: true (tsconfig.json) is a compiler flag for .

When strictNullChecks is false, null and undefined are effectively ignored by the language. This can lead to unexpected errors at runtime. Setting strictNullChecks to true will raise an error that you have not made a guarantee that the value exists before trying to use it.

Resources:

24 questions
1
vote
2 answers

How to tell Typescript that *in this instance* a function's return type is never null

I'm trying to get typescript strictNullChecks working in an Angular 5 project. I have a form: this.signinForm = this.fb.group({ emailAddress: ['', NGValidators.isEmail()], password: ['', Validators.required], rememberMe: false, }); I can get…
John
  • 7,008
  • 3
  • 33
  • 62
0
votes
0 answers

Typescript: How are file dependencies calculated for incremental compilation and for strictNull checking

We have a large Typescript project and we are trying to improve incremental compilation time, which is sometimes dominating development time. For many files, if we follow all import statements, we would reach most files of the project, so…
0
votes
1 answer

Can I disable distinguishing between null and undefined in TypeScript strict null-checking mode?

I'm currently converting a large TypeScript codebase to strict null-checks. The codebase has many types with optional members: interface MyInterface { member1?: number; member2?: string; } Furthermore, it uses a type Nullable = T | null, and…
cheesus
  • 11,077
  • 10
  • 64
  • 122
0
votes
1 answer

Type alias from property that might be null with strictNullChecks

I am using graphql-codegen/typescript-apollo-angular to generate typescript code can be useed in our Angular application. We decided to enable strictNullChecks the only issue is that we use the following pattern to specify the types of inner nodes…
Jonas Osburg
  • 1,528
  • 1
  • 13
  • 16
0
votes
2 answers

Typescript strictNullChecks does not narrow type

I have a simple case when strictNullChecks does not narrow type even though I explicitly check for undefined. interface WideType { one: { two: number } | undefined; } interface NarrowType { one: { two: number }; } const example = (value:…
Yan
  • 890
  • 1
  • 7
  • 12
0
votes
1 answer

TypeScript: Can I check if a type contains undefined even when strictNullChecks is false?

We had an Issue in redux-starter-kit where a user of the library had strictNullChecks disabled and one of our type tests was short-cicuiting, returning types for a different case. This test should return the True-Parameter or the False-Parameter…
phry
  • 4,685
  • 1
  • 10
  • 21
0
votes
0 answers

Typescript Strict Null Checks on Objects With optional keys

I am introducing the strictNullchecks compiler option in our Angular project and have come across this issue. error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. replaceTokens(menuItemList:…
James
  • 1,335
  • 1
  • 10
  • 19
0
votes
1 answer

Typescript strictNullChecks error when not possible

I am attempting to turn on the strictNullChecks setting for my project, but have a rather curious error in the following snippet of code: toasters.forEach((toster: ToasterObject) => { if (toaster.brandName) { //This line works just fine …
dmoore1181
  • 1,188
  • 1
  • 15
  • 41
-1
votes
1 answer

Can I solve this one without strictNullChecks: false?

I wonder how can I solve this without setting strictNullchecks to false. if (someArray.find(element => element.id === x.id) { return someArray.find(element => element.id === x.id).message } or const x = someArray.find(element => element.id ===…
Noah
  • 3
  • 2
1
2