Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement strictNullChecks in angular 4

I have tried to implement strictNullChecks in angular 4 application.

I have just added "strictNullChecks": true in tsconfig.json

When I run the application ng serve I got this below error.

ERROR in [at-loader] ./node_modules/@angular/forms/src/model.d.ts:244:39 
TS2459: Type '{ onlySelf?: boolean | undefined; emitEvent?: boolean | 
undefined; } | undefined' has no property 'emitEvent' and no string index signature.

What's going wrong? How can we implement strictNullChecks in angular 4?

like image 360
Ramesh Rajendran Avatar asked Jul 04 '17 10:07

Ramesh Rajendran


People also ask

How do you add strictNullChecks?

To enable StrictNullChecks open tsconfg. sys and add "strictNullChecks": true under the compilerOptions . With this set to true , you'll get a type error if you try to use null or undefined wherever Typescript expects a concrete type.

How to enable strict mode in Angular?

To opt into the strict mode, you need to create a new Angular CLI app, specifying the --strict flag: The command above will generate a workspace with the following settings enabled on top of the defaults: Strict mode in TypeScript, as well as other strictness flags recommended by the TypeScript team.

How do you enforce a strict null check in TypeScript?

In Typescript to enforce strict null checks in tsconfig. json file, we need to enable “strictNullChecks” to true. When “strictNullChecks” is false, the language generally ignores variables of type null and undefined. If null and undefined is used in places where a definite value is expected, it raises an error.

What is strictNullChecks?

--strictNullChecks strictNullChecks switches to a new strict null checking mode. In strict null checking mode, the null and undefined values are not in the domain of every type and are only assignable to themselves and any (the one exception being that undefined is also assignable to void ).


1 Answers

Angular 2.x-4x

When you enable strictNullChecks, it enables it for all TypeScript files, which includes libraries.

To enable strictNullChecks in an Angular CLI project set skipLibCheck to true in your tsConfig.

Angular 5.x+ has addressed this issue.

like image 134
cgatian Avatar answered Oct 11 '22 08:10

cgatian