46

I'm trying to migrate an ES6 project to typescript. This is my first attempt at writing a typescript module in NodeJS.

It seems to work better in Angular-CLI so far.

I've got it compiling using command line tsc, but I'm not sure how to display errors and intellisense in the code editor?

In a directory I have the two files shown below. When it compiles it, as expected throws a compile error: Supplied parameters do not match any signature of cal l target.. This is fine.

But VSCode is not showing any errors in the editor, even if I make a deliberate syntax error like taking out a bracket, or type errors like this one. How do I get VSCode to show inline syntax or compiler errors in the editor for .ts files?

validation-error.ts

/**
 * Wrapper for a particular validation error.
 */
export class ValidationError extends Error {
  private type: string;

  constructor(error: any) {
    super(error);
    Error.captureStackTrace(this, this.constructor);
    this.message = error.message;
    this.type = 'ValidationError';
  }
}

Then I'm trying to write simple spec to test out the workflow:

validation-error.spec.ts

import { ValidationError } from './validation-error';
import * as should from 'should';

describe('Validation Error', () => {
  it('should create a new instance', () => {
    const instance = new ValidationError();
    should.exist(instance);
  });
});

Edited Here:

I'm still plugging away at this - I've setup tsc to run automatically with this job in tasks.json:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "taskName": "tsc",
  "command": "tsc",
  "isShellCommand": true,
  "args": ["-w", "-p", "."],
  "problemMatcher": "$tsc-watch",
  "echoCommand": true
}

I suspect that if the errors were reported properly using $tsc-watch, the error would probably also show up in the editor. When I run the task I get output like:

running command$ tsc -w -p .
src/hello.ts(15,1): error TS2346: Supplied parameters do not match any signature of call target.
4:24:40 PM - Compilation complete. Watching for file changes.

But there are no problems reported in the Problems view - even though clearly there's a compiler issue.

Got the $tsc-watch setting from this page of the docs: https://code.visualstudio.com/docs/editor/tasks

2
  • Do you have a tsconfig.json file in your project (opened directory) ? Commented May 11, 2017 at 7:34
  • I do have it already. Commented May 11, 2017 at 7:55

9 Answers 9

83

For me the problem was resolved by setting Typescript validation to true in VSCode settings:

"typescript.validate.enable": true,

I had turned this off in my workspace settings in the past and forgot!

So make sure to double check that this setting is not set to false in your user settings, workspace settings or folder settings.

enter image description here

For instance the rule I was trying to get work was checking for undefined variables which was immediately fixed when I set validate to true.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

"I had turned this off in my workspace settings in the past and forgot!". hahaha omg... i want my 5 hours back. 😢. Thanks!!!!!
8

The other answers (most before year 2020) did not work for me.

According to this feature request in Microsoft's VS Code repository, do the following steps:

  1. In your settings.json add:
"typescript.validate.enable": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
  1. In your tsconfig.json add:
"include": [
    "src",
    "global.d.ts",
  ],
"exclude": [
    "node_modules",
    "plugins",
    "public"
  ]

Wait a while (or restart VS Code) in order to see a list of errors shown in the open files and added in the problems panel.

Comments

6

I ran aground with this issue, managed to solve it by adding "typescript.validate.enable": true to my local settings.json file in the .vscode directory. My settings tell me that the typescript validator is enabled for VS code globally, but I wasn't able to see inline TS errors until I added the local settings file.

Comments

5

Even without having installed TypeScript locally or globally, the following setup provides inline errors.

C:/temp
  index.ts
  tsconfig.json

index.ts

let x: number;
x = "foo";

tsconfig.json

{ }

Here is a screenshot that shows the inline error in x.

enter image description here

Please try that setup and report back on what happens.

2 Comments

Interesting. I wonder why mine was not working, I copied tsconfig from somewhere so perhaps there's some version issues or something. I eventually did get it working yesterday anyway with the tsc problem resolver - at least I think that's why it worked. It seemed to be a bug where on first compile it wasn't listing the errors in VS Code, but if I changed a file while it's in watch mode, then the errors were displayed as expected. So it's probably just an error in some combination of things in my setup.
An empty tsconfig.json? I doubt this is a working solution.
2

I just closed & restarted my VS Code and it started showing typescript errors like before.

If this doesn't work, I'd suggest restarting your computer system.

1 Comment

You can also issue the "Restart TS Server" command to just restart the piece that shows you errors.
0

VSCode IntelliSense supports Typescript without the need of ANY setup.

  • Ensure that typescript is globally installed: npm i -g typescript
  • No VSCode setting needs to be changed.
  • No tsconfig.json setting required.
  • Even if u do not create tsconfig.json, VSCode will still catch errors in Typescript.

References:

  1. https://code.visualstudio.com/docs/languages/typescript#_intellisense
  2. https://code.visualstudio.com/docs/editor/intellisense#_intellisense-for-your-programming-language

1 Comment

Always better to have typescript as a local dependency, and vscode set to use the locally available typescript version. It's the only reliable way to avoid version mismatches locally AND in the CI pipelines, per project.
0

In case it helps anyone coming here for the same reason but with a different root cause...

For me, the issue resided with my tsconfig.json where the "files" option was specified, which limited the "files to include in the program".

Comments

0

Cmd + shift + P to open the command input, search for typescript and choose TypeScript: Select TypeScript Version and choose the one in your node_modules (it had VSCode's version by default).

This fixed it for me.

Comments

-2

1.Edit in setting.json

"editor.hover.enabled": true

2.Settings > TypeScript › Validate: Enable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.