microsoft / microsoft/TypeScript

Missing 'used before declaration' error with IIFE

Open
#29,135 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.