microsoft / microsoft/TypeScript
Inconsistent assignment analysis for async arrow IIFE's regarding class property declarations (sugar vs constructor assigning)
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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