question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Including full error range in TSC output

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
jamiebuildscommented, Jun 12, 2020

Lots of times, JSON output is useful for connecting various build tools.

Right now it’s already possible to use Regex to parse out error messages:

/^(.*)\((\d+),(\d+)\): (.*) (TS\d+): (.*)$/gm
// with named capture groups
/^(?<filepath>.*)\((?<line>\d+),(?<column>\d+)\): (?<category>.*) (?<type>TS\d+): (?<message>.*)$/gm

However, this isn’t very portable, it’d be much nicer if you could specify a way to emit errors/warnings as JSON.

tsc --noEmit --json # or whatever flag
interface TSCError {
  filepath: string
  line: number
  column: number
  category: "error" | "warning"
  type: "TS0000" | "TS0001" | ...,
  message: string
}

interface TSCJSONOutput {
  errors: TSCError[]
}

Other output can be printed to stderr, but stdout should be pipe-able as valid JSON.

tsc --noEmit --json | jq .errors
6reactions
weswighamcommented, Mar 15, 2019

@mjbvz How would you feel about a --formatter json command line option for providing diagnostics in a machine readable format from the command line tools? Or is that too far and away from the current problem matcher infrastructure to be useful?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes ... a wide range of type checking behavior that results in stronger guarantees of ...
Read more >
How to find the cause for an undescriptive TypeScript compiler ...
Run tsc -b --verbose. Side notes. The compiling takes long and eats a lot of memory before that error message appears. When I...
Read more >
TypeScript errors and how to fix them
Below you find a list of common TypeScript errors along with the buggy code ... error TS1361: ' Range ' cannot be used...
Read more >
Understanding TypeScript's “Compilation Process” & the ...
However, the tsc compiler (short for TypeScript compiler) needs a JSON ... and outputs the JavaScript with .js extension by keeping the same ......
Read more >
1839095 – VM fails to migrate between identical hosts not ...
It is possible to reproduce this issue even with a single host and not involving migration. Just try to start a domain configured...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found