Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

TypeScript MSBuild compilation options


May 07, 2021 TypeScript


Table of contents


Use the compilation option in MSBuild

Overview

Compilation options can be specified through MSBuild properties in projects that use MSBuild.

Example

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
  <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
  <TypeScriptSourceMap>true</TypeScriptSourceMap>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
  <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
  <TypeScriptSourceMap>false</TypeScriptSourceMap>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets"
        Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />

Mapping

Compilation options MsBuild property name The available value
--declaration TypeScriptGeneratesDeclarations Boolean value
--module TypeScriptModuleKind AMD CommonJs UMD or System
--target TypeScriptTarget ES3 , ES5 , or ES6
--charset TypeScriptCharset
--emitBOM TypeScriptEmitBOM Boolean value
--emitDecoratorMetadata TypeScriptEmitDecoratorMetadata Boolean value
--experimentalDecorators TypeScriptExperimentalDecorators Boolean value
--inlineSourceMap TypeScriptInlineSourceMap Boolean value
--inlineSources TypeScriptInlineSources Boolean value
--locale Automatic The value automatically set to PreferredUILang
--mapRoot TypeScriptMapRoot The file path
--newLine TypeScriptNewLine CRLF or LF
--noEmitOnError TypeScriptNoEmitOnError Boolean value
--noEmitHelpers TypeScriptNoEmitHelpers Boolean value
--noImplicitAny TypeScriptNoImplicitAny Boolean value
--noUnusedLocals TypeScriptNoUnusedLocals Boolean value
--noUnusedParameters TypeScriptNoUnusedParameters Boolean value
--noLib TypeScriptNoLib Boolean value
--noResolve TypeScriptNoResolve Boolean value
--out TypeScriptOutFile The file path
--outDir TypeScriptOutDir The file path
--preserveConstEnums TypeScriptPreserveConstEnums Boolean value
--removeComments TypeScriptRemoveComments Boolean value
--rootDir TypeScriptRootDir The file path
--isolatedModules TypeScriptIsolatedModules Boolean value
--sourceMap TypeScriptSourceMap The file path
--sourceRoot TypeScriptSourceRoot The file path
--strictNullChecks TypeScriptStrictNullChecks Boolean value
--suppressImplicitAnyIndexErrors TypeScriptSuppressImplicitAnyIndexErrors Boolean value
--suppressExcessPropertyErrors TypeScriptSuppressExcessPropertyErrors Boolean value
--moduleResolution TypeScriptModuleResolution Classic or Node
--experimentalAsyncFunctions TypeScriptExperimentalAsyncFunctions Boolean value
--jsx TypeScriptJSXEmit React or Preserve
--reactNamespace TypeScriptReactNamespace string
--skipDefaultLibCheck TypeScriptSkipDefaultLibCheck Boolean value
--allowUnusedLabels TypeScriptAllowUnusedLabels Boolean value
--noImplicitReturns TypeScriptNoImplicitReturns Boolean value
--noFallthroughCasesInSwitch TypeScriptNoFallthroughCasesInSwitch Boolean value
--allowUnreachableCode TypeScriptAllowUnreachableCode Boolean value
--forceConsistentCasingInFileNames TypeScriptForceConsistentCasingInFileNames Boolean value
--allowSyntheticDefaultImports TypeScriptAllowSyntheticDefaultImports Boolean value
--noImplicitUseStrict TypeScriptNoImplicitUseStrict Boolean value
--project VS does not support it
--watch VS does not support it
--diagnostics VS does not support it
--listFiles VS does not support it
--noEmit VS does not support it
--allowJs VS does not support it
VS has a special option TypeScriptAdditionalFlags Any compilation option

What options are supported in the Visual Studio version I'm using?

Find C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets . . . MSBuild . . . Microsoft . . . VisualStudioVersion . . . TypeScript . The available MSBuild XML tags are tsc compilation options.

ToolsVersion

The property values in the engineering file indicate the version number of <TypeScriptToolsVersion>1.7</TypeScriptToolsVersion> the build (in this case 1.7), which allows a project to compile on different machines using a fixed version.

If TypeScriptToolsVersion is built using the latest version of the compiler installed on the machine.

If the user is using an updated version of TypeScript, they will see a dialog box that prompts them to upgrade the project the first time they load it.

TypeScriptCompileBlocked

If you use other build tools (e.g., gulp, grunt, etc.) and use VS as a development and debugging tool, set up the project with <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> This way VS will only provide you with editing functionality, not build it when you press F5.