Skip to content

Enable strictNullChecks mode for aio codebase #20646

Closed

Description

@IgorMinar

aio doesn't use the strictNullChecks tsc mode, primarily because the mode didn't exist when we started the project.

Having this mode on would help us catch more bugs using the typechecker and would also help us better understand the TS upgrade pain for users with this mode on (currently we have this mode on in g3 and angular framework code base, but we don't have any of our non-g3 apps using that mode).

Activity

  1. added
    featureLabel used to distinguish feature request from other issues
    on Nov 27, 2017
  2. gkalpak commented on Nov 28, 2017

    @gkalpak
    Member

    Should we enable all --strict checks? Please? 😛
    From the TS handbook:

    --strict
    Enable all strict type checking options.
    Enabling --strict enables --noImplicitAny, --noImplicitThis, --alwaysStrict, --strictNullChecks and --strictFunctionTypes.

  3. trotyl commented on Nov 28, 2017

    @trotyl
    Contributor

    @gkalpak the --strict master option in tsconfig will break Angular in TypeScript 2.7 due to the new --strictPropertyInitialization option. It was mentioned in microsoft/TypeScript#15360 and microsoft/TypeScript#20117.

  4. gkalpak commented on Nov 28, 2017

    @gkalpak
    Member

    Thx for the heads-up 👍

    We can always explcitly opt-out of specific options. That's better than opt into imo.
    Also, I am not sure why this is incompatible with Angular (why can't you initialize input properties anyway)?

    Also, we just landed support for TS 2.5. Let's worry about 2.7 when we get there 😃

  5. trotyl commented on Nov 28, 2017

    @trotyl
    Contributor

    I am not sure why this is incompatible with Angular

    In Angular we always initialize input properties AFTER constructor and before ngOnInit, so that's an error in TypeScript as it cannot detect the initialization (and if the properties are not nullable).

    We can always explcitly opt-out of specific options.

    That's a good idea, but Angular CLI seems unable to auto-update tsconfig, so may not apply there (sorry for off-topic, still fine for angular.io). 😄

  6. gkalpak commented on Nov 28, 2017

    @gkalpak
    Member

    I mean there is nothing stopping you from initializing input properties in the component:

    @Component({
      template: 'Hello, {{ name }}!',
    })
    class GreetingComponent {
      @Input() name = 'world';
    }
  7. trotyl commented on Nov 28, 2017

    @trotyl
    Contributor

    That's true, but I guess most input properties may not have a default value? 😄

  8. gkalpak commented on Nov 28, 2017

    @gkalpak
    Member

    You can always explicit | null = null 😃
    Just to be clear, we are talking about just the angular.io app. But even if we end up turning --strictPropertyInitialization off, it is better to be "strict by default" 😃

  9. danwulff commented on Nov 28, 2017

    @danwulff

    I feel like enabling the --strict flag, would provide for the safest / best use of typescript protection going forward. This would definitely be an undertaking for all of Angular but maybe shooting for this in release 6.0 could be a possibility? I hope @IgorMinar and the Angular team would at least take this into consideration.

    From the typescript 2.3 release notes: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#new---strict-master-option

    New checks added to TypeScript are often off by default to avoid breaking existing projects. While avoiding breakage is a good thing, this strategy has the drawback of making it increasingly complex to choose the highest level of type safety, and doing so requires explicit opt-in action on every TypeScript release. With the --strict option it becomes possible to choose maximum type safety with the understanding that additional errors might be reported by newer versions of the compiler as improved type checking features are added.

  10. added a commit that references this issue on Jan 12, 2018
    71dd92b
  11. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  12. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

featureLabel used to distinguish feature request from other issues

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions