skoll
skoll

Reputation: 2452

Suppress TypeScript errors in Visual Studio 2015

Is it possible to suppress errors in Visual Studio (when working with TypeScript)?

Specifically I'd like to suppress the is declared but never used-error. When debugging I need to comment out some code every once in a while, but Visual Studio refuses to build the project if I have declared a function I'm not using.

Why is that an error to begin with? Shouldn't it be a warning?

Upvotes: 1

Views: 744

Answers (2)

skoll
skoll

Reputation: 2452

If using a csproj -file, you can get rid of the is declared but never used -error by removing the line

<TypeScriptNoUnusedLocals>True</TypeScriptNoUnusedLocals>

or changing it to

<TypeScriptNoUnusedLocals>False</TypeScriptNoUnusedLocals>

Some other settings for suppressing errors:

<TypeScriptAllowUnreachableCode>True</TypeScriptAllowUnreachableCode> <TypeScriptNoUnusedParameters>False</TypeScriptNoUnusedParameters> <TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>

Upvotes: 0

ToastyMallows
ToastyMallows

Reputation: 4273

You should use a tsconfig.json file, more information here:

http://www.typescriptlang.org/docs/handbook/tsconfig-json.html

It might take some time to get it configured the way you have your project configured now, but there is a setting to not error when there are unused locals:

{
    "compilerOptions": {
        "noUnusedLocals": false
    }
}

There are also a couple other settings, noUnusedParameters, allowUnsedLabels and allowUnreachableCode which may help you.

The schema for the JSON file is available here: http://json.schemastore.org/tsconfig

Visual Studio should know that the JSON file is a tsconfig file and provide you with IntelliSense information from that schema file.

Upvotes: 3

Related Questions