microsoft / microsoft/TypeScript
Missing 'used before declaration' error with IIFE
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.2.1
Search Terms:
Code
class C {
a = (() => this.b)();
b = '';
}
Expected behavior:
Error Property 'b' is used before its initialization.
Control flow analysis inlines IIFEs, but it seems the use-before-declare check doesn't.
Actual behavior:
No error
Playground Link: https://agentcooper.github.io/typescript-play/#code/MYGwhgzhAEDC0G8BQ1XTNAvNAFDglFgHzQAuAFgJYQB0ARvgQNwpp1bQDknLAvkA
Related Issues: Found while investigating https://github.com/Microsoft/TypeScript/issues/29125
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 with the TypeScript 3.2.1 playground example from the issue and compare its behavior with the related issue #29125. Trace how control-flow analysis handles the IIFE versus the use-before-initialization check. Done means the shown class produces the expected "Property 'b' is used before its initialization" error.
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