Skip to content

Forgotten 'await' error doesn't account for strictPropertyInitialization #43071

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

We recently ran into some breaks in #43004 (comment) as a result of #25330; however, I think this might be a bigger change than we anticipate.

For one, we don't check whether the value is used after checking the value. For another, we don't really think about class properties, which aren't reliable unless using strictPropertyInitialization.

// @strictNullChecks: true
// @strictPropertyInitialization: false

class C {
  yadda: Promise<number>;

  async doStuff() {
    this.yadda = Promise.resolve(42);
  }
}

async function f() {
  let obj = new C();
  if (obj.yadda) {
    await obj.yadda;
  }

  let x = new C().yadda;
  if (x) {
    await x;
  }
}

Finally, there's some sort of bug where this is plainly giving false positives.

let x: Promise<string>;

setTimeout(() => {
  x = Promise.resolve("");
})

setTimeout(() => {
  // this should NOT be an error
  if (x) {
    x;
  }
})

I guess the question is: should these be errors?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions