Skip to content

Enable strictPropertyInitialization #78168

@alexdima

Description

@alexdima

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:

  • vs/base/browser/ui/tree/asyncDataTree.ts @joaomoreno
  • src/vs/workbench/api/common/extHostTypes.ts @jrieken
  • src/vs/workbench/api/common/extHostWebview.ts @mjbvz

Metadata

Metadata

Labels

debtCode quality issuesengineeringVS Code - Build / issue tracking / etc.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions