microsoft / microsoft/TypeScript

Inconsistent assignment analysis for async arrow IIFE's regarding class property declarations (sugar vs constructor assigning)

Open
#38,929 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: check: Control Flow
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 4.0.0-dev.202000519

Search Terms: async IIFE Property is used before being assigned class declaration

Code

This works fine:

class MyClass {
	public foo = 0;

	constructor() {
		(async () => this.foo + 5)();
	}
}

This, on the other hand, errors:

class MyClass {
	public foo: number;

	constructor() {
		this.foo = 0;
		(async () => this.foo + 5)(); // errors?
	}
}

These two code snippets should be treated the same because the first snippet is sugar for the second.

Expected behavior: (async () => this.foo + 5)() should not have the error "Property 'foo' is used before being assigned."

Actual behavior: It errors

Playground Link: Here

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two class examples in the linked TypeScript Playground and compare the assignment analysis for the class-property and constructor-assignment forms. Investigate the handling of async arrow IIFEs and verify that the reported "used before being assigned" error is absent for the constructor-assignment case while the existing behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.