microsoft / microsoft/TypeScript

Including full error range in TSC output

Open
#30,433 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

From https://github.com/Microsoft/vscode/issues/70465

Repo

  1. For the TS code with strict enabled:

    const obj = {
        prop: Date.now() ? 'str' : undefined
    }
    
    obj.prop.toLowerCase();
    
  2. Run a tsc task in VS Code to see reported errors (make sure to close the ts file as well)

Problem
We currently only report the potential undefined access error on obj in the line obj.prop.toLowerCase();. The correct range should span obj.prop.

The root cause of this is that VS Code's problem matcher does not have the full range of the error from tsc, only the start line and column. Here's the tsc output:

src/index.ts:7:1 - error TS2532: Object is possibly 'undefined'.

7 obj.prop.toLowerCase();
  ~~~~~~~~

With the current tsc output, there is also no way to extract the full range of the error.

Request
Somewhere in the line src/index.ts:7:1 - error TS2532: Object is possibly 'undefined'. , add the end position as well so that tooling can properly highlight it. We would want to do this in a way that doesn't detract from the error's human readability. This needs some thought

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

Reproduce the issue with the provided strict TypeScript example and inspect the tsc diagnostic output for TS2532. Determine how to include the diagnostic end position without reducing human readability; done means tooling can extract the full range and the existing error remains understandable.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.