Solvedangular Allow angular 2 applications to compile in strictNullChecks mode

I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting

Current behavior

When trying to compile an ng2 application with typescript 2.0 strictNullChecks turned on the compiler runs into errors.

Expected behavior

Expect that ng2 would support use with strictNullChecks.

Reproduction of the problem

Reproduced by taking the quick start application and setting the strictNullChecks option true in tsconfig.json. (see: https://github.com/abierbaum/quickstart)

When doing this and running npm run tsc the following error is shown:

> angular-quickstart@1.0.0 tsc /home/allenb/Source/quickstart
> tsc

node_modules/@angular/core/src/util/decorators.d.ts(11,5): error TS2411: Property 'extends' of type 'Type<any> | undefined' is not assignable to string index type 'Function | any[] | Type<any>'.
node_modules/@angular/platform-browser/src/dom/dom_renderer.d.ts(25,22): error TS2420: Class 'DomRenderer' incorrectly implements interface 'Renderer'.
  Types of property 'animate' are incompatible.
    Type '(element: any, startingStyles: AnimationStyles | undefined, keyframes: (AnimationKeyframe | undef...' is not assignable to type '(element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number,...'.
      Type 'AnimationPlayer | undefined' is not assignable to type 'AnimationPlayer'.
        Type 'undefined' is not assignable to type 'AnimationPlayer'.

Other similar errors occur with larger projects.

What is the motivation / use case for changing the behavior?

strictNullChecks is a recommended best practices for new typescript code and it would be great if we could use this with ng2 applications.

35 Answers

✔️Accepted Answer

How about using skipLibCheck? Before I use it, I got following errors. They are all gone away now.

[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/core/src/util/decorators.d.ts:11:5
    Property 'extends' of type 'Type<any> | undefined' is not assignable to string index type 'Function | any[] | Type<any>'.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:375:27
    Type '{ onlySelf?: boolean | undefined; emitEvent?: boolean | undefined; emitModelToViewChange?: boolea...' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:375:37
    Type '{ onlySelf?: boolean | undefined; emitEvent?: boolean | undefined; emitModelToViewChange?: boolea...' has no property 'emitEvent' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:375:48
    Type '{ onlySelf?: boolean | undefined; emitEvent?: boolean | undefined; emitModelToViewChange?: boolea...' has no property 'emitModelToViewChange' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:375:71
    Type '{ onlySelf?: boolean | undefined; emitEvent?: boolean | undefined; emitModelToViewChange?: boolea...' has no property 'emitViewToModelChange' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:422:29
    Type '{ onlySelf?: boolean | undefined; } | undefined' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:544:9
    Type '{ onlySelf?: boolean | undefined; } | undefined' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:570:9
    Type '{ onlySelf?: boolean | undefined; } | undefined' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:605:25
    Type '{ onlySelf?: boolean | undefined; } | undefined' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:708:29
    Type '{ onlySelf?: boolean | undefined; } | undefined' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:731:31
    Type '{ onlySelf?: boolean | undefined; } | undefined' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/forms/src/model.d.ts:765:25
    Type '{ onlySelf?: boolean | undefined; } | undefined' has no property 'onlySelf' and no string index signature.
[default] /Users/akira/src/github.com/springboot-angular2-tutorial/angular2-app/node_modules/@angular/platform-browser/src/dom/dom_renderer.d.ts:25:22
    Class 'DomRenderer' incorrectly implements interface 'Renderer'.
  Types of property 'animate' are incompatible.
    Type '(element: any, startingStyles: AnimationStyles | undefined, keyframes: (AnimationKeyframe | undef...' is not assignable to type '(element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number,...'.
      Type 'AnimationPlayer | undefined' is not assignable to type 'AnimationPlayer'.
        Type 'undefined' is not assignable to type 'AnimationPlayer'.
[default] Checking finished with 13 errors

Other Answers:

We'll investigate the possibility to roll this out without breaking changes.

I'd consider upgrading from ts 1.8 to 2.0 a nuisance compared to upgrading
from rc to rc :-)

Am 27.09.2016 17:13 schrieb "Victor Berchet" notifications@github.com:

now that TS 2.0 is out, what's the point in supporting 1.8?

Because big applications can't migrate overnight and we don't want to
break our users.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#11844 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAH8NxZ3zhDhK4ISyKBDA2JZ2Tx4LgEoks5quTE5gaJpZM4KEbdI
.

@rkirov now that TS 2.0 is out, what's the point in supporting 1.8?

More Issues: