Skip to content

Enable strictPropertyInitialization #78168

Closed

Description

We have enabled strictNullChecks, but the TS compiler doesn't catch the following:

class A {
  prop: number;
  constructor() {
    // forgot to assign to prop, so it will be undefined...
  }
}

Possible fixes:

class A {
  prop: number;
  constructor() {
    this.prop = 5; // Assign the property in the ctor
  }
}
class A {
  prop!: number; // use exclamation mark to suppress the error
  constructor() {
    this._init();
  }
  private _init() {
    this.prop = 5;
  }
}

In order to get errors for such cases, we need to add "strictPropertyInitialization": true to our tsconfig.json.

@microsoft/vscode it would be nice if we could tackle some of these errors during debt week.

[edit 11.11]: There are 8 errors left:

Activity

  1. added
    engineering
    on Jul 30, 2019
  2. isidorn commented on Jul 30, 2019

    @isidorn

    Adding it to next milestone so it shows up in my issue query for debt week.
    If we do not tackle it completely we can always move it to the next one afterwards.

  3. self-assigned this
    on Aug 1, 2019
  4. removed their assignment
    on Aug 5, 2019
  5. 100 remaining items

  6. sandy081 commented on Nov 11, 2019

    @sandy081
    Member

    ✅

  7. added 2 commits that reference this issue on Nov 11, 2019
  8. bpasero commented on Nov 11, 2019

    @bpasero
    Contributor

    Remaining:
    image

    Matt Bierner (@mjbvz) d.ts & webview
    João Moreno (@joaomoreno) async tree
    Johannes Rieken (@jrieken) extHostTypes (call hierarchy related it seems)

  9. mjbvz commented on Nov 11, 2019

    @mjbvz
    Contributor

    Fixed extHostWebview again. Down to four errors in three files:

    • viewsViewlet.ts
    • `asyncDataTree.ts
    • extHostTypes.ts
  10. removed their assignment
    on Nov 11, 2019
  11. sandy081 commented on Nov 11, 2019

    @sandy081
    Member

    Ping Alex Ross (@alexr00) for viewsViewlet.ts

  12. bpasero commented on Nov 12, 2019

    @bpasero
    Contributor

    I went ahead and resolved those so that we do not have to play the catch up game all the time 👍

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

Metadata

Metadata

Labels

debtengineering

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions