microsoft / microsoft/TypeScript

Should intellisense suggest block scoped values before they are declared?

Open
#28,475 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: LS: Completion Lists Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Currently intellisense suggests every block scoped declaration in scope, even if the suggestion is located within the TDZ. When accepting that suggestion, TypeScript issue an used before its declaration error:

new /**/; // suggests 'Clazz', which results in an error
class Clazz {}

function test(
  foo = /**/, // suggests `foo`, `bar` and `baz`, all of them result in an error
  bar = /**/, // suggests `bar` and `baz`, both result in an error
) {
  let baz = 1;
}

Should intellisense filter out suggestions that would result in an error? If so, it should probably use the same condition as the checker.

Related: #28472 #28471

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

No files or tests are named. Start by locating the IntelliSense completion logic for block-scoped declarations and compare its filtering with the checker's used-before-declaration condition; done means TDZ-invalid suggestions such as Clazz, foo, bar, and baz are excluded while valid suggestions remain available.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.