microsoft / microsoft/TypeScript

Feature Request: add TypeChecker API to query if identifier is definitely assigned

Open
#20,221 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: API In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Currently it's not possible to query CFA. I need to find out if an identifier is definitely assigned. This logic is part of checkIdentifier and is not accessible outside of that function.

My use case is the TSLint rule no-unnecessary-type-assertion where we need to identify false positives. The current implementation compares the type before and after the non-null-assertion. That doesn't work well for identifiers that are not definitely assigned, because the assertion suppresses TS2454 and can therefore not be removed.

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 reading the control-flow analysis logic in checkIdentifier, which currently contains the definitely-assigned check. Trace how the TSLint no-unnecessary-type-assertion rule needs to query that result and define the public TypeChecker API boundary. Done means callers can determine whether an identifier is definitely assigned without relying on internal checkIdentifier behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.