Using the CLI

Running tsc locally will compile the closest project defined by a tsconfig.json, you can compile a set of TypeScript files by passing in a glob of files you want.

  1. # Run a compile based on a backwards look through the fs for a tsconfig.json
    tsc
    # Transpile just the index.ts with the compiler defaults
    tsc index.ts
    # Transpile any .ts files in the folder src, with the default settings
    tsc src/*.ts
    # Transpile any files referenced in with the compiler settings from tsconfig.production.json
    tsc --project tsconfig.production.json

Compiler Options

If you’re looking for more information about the compiler options in a tsconfig, check out the TSConfig Reference

OptionTypeDefaultDescription
—allowJsbooleanfalseAllow JavaScript files to be compiled.
—allowSyntheticDefaultImportsbooleanmodule === “system” or —esModuleInteropAllow default imports from modules with no default export. This does not affect code emit, just typechecking.
—allowUmdGlobalAccessbooleanfalseAllow accessing UMD globals from modules.
—allowUnreachableCodebooleanDo not report errors on unreachable code.
—allowUnusedLabelsbooleanfalseDo not report errors on unused labels.
—alwaysStrictbooleanfalseParse in strict mode and emit “use strict” for each source file
—assumeChangesOnlyAffectDirectDependenciesbooleanfalseHave recompiles in —incremental and —watch assume that changes within a file will only affect files directly depending on it
—baseUrlstringBase directory to resolve non-relative module names. See Module Resolution documentation for more details.
—build
-b
booleanfalseBuilds this project and all of its dependencies specified by Project References. Note that this flag is not compatible with others on this page. See more here
—charsetstring“utf8”The character set of the input files.
—checkJsbooleanfalseReport errors in .js files. Use in conjunction with —allowJs.
—compositebooleantrueEnsure TypeScript can determine where to find the outputs of the referenced project to compile project.
—declaration
-d
booleanfalseGenerates corresponding .d.ts file.
—declarationDirstringOutput directory for generated declaration files.
—declarationMapbooleanfalseGenerates a sourcemap for each corresponding .d.ts file.
—diagnosticsbooleanfalseShow diagnostic information.
—disableSizeLimitbooleanfalseDisable size limitation on JavaScript project.
—downlevelIterationbooleanfalseProvide full support for iterables in for..of, spread and destructuring when targeting ES5 or ES3.
—emitBOMbooleanfalseEmit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
—emitDeclarationOnlybooleanfalseOnly emit .d.ts declaration files.
—emitDecoratorMetadata[1]booleanfalseEmit design-type metadata for decorated declarations in source. See issue #2577 for details.
—esModuleInteropbooleanfalseEmit importStar and importDefault helpers for runtime babel ecosystem compatibility and enable —allowSyntheticDefaultImports for typesystem compatibility.
—experimentalDecorators[1]booleanfalseEnables experimental support for ES decorators.
—extendedDiagnosticsbooleanfalseShow verbose diagnostic information
—forceConsistentCasingInFileNamesbooleanfalseDisallow inconsistently-cased references to the same file.
—generateCpuProfilestringprofile.cpuprofileGenerates a cpu profile at the given path. Passing an existing directory name instead of a file path will cause a timestamp-named profile to be generated in that directory instead.
—help
-h
Print help message.
—importHelpersbooleanfalseImport emit helpers (e.g. extends, rest, etc..) from tslib
—incrementalbooleantrue if composite is on, false otherwiseEnable incremental compilation by reading/writing information from prior compilations to a file on disk. This file is controlled by the —tsBuildInfoFile flag.
—inlineSourceMapbooleanfalseEmit a single file with source maps instead of having a separate file.
—inlineSourcesbooleanfalseEmit the source alongside the sourcemaps within a single file; requires —inlineSourceMap or —sourceMap to be set.
—initInitializes a TypeScript project and creates a tsconfig.json file.
—isolatedModulesbooleanfalsePerform additional checks to ensure that separate compilation (such as with transpileModule or @babel/plugin-transform-typescript) would be safe.
—jsxstringSupport JSX in .tsx files: “react”, “preserve”, “react-native”. See JSX.
—jsxFactorystring“React.createElement”Specify the JSX factory function to use when targeting react JSX emit, e.g. React.createElement or h.
—jsxFragmentFactorystring“React.Fragment”Specify the JSX fragment factory function to use when targeting react JSX emit, e.g. Fragment.
—keyofStringsOnlybooleanfalseResolve keyof to string valued property names only (no numbers or symbols).
—libstring[]List of library files to be included in the compilation.
Possible values are:
ES5
ES6
ES2015
ES7
ES2016
ES2017
ES2018
ESNext
DOM
DOM.Iterable
WebWorker
ScriptHost
ES2015.Core
ES2015.Collection
ES2015.Generator
ES2015.Iterable
ES2015.Promise
ES2015.Proxy
ES2015.Reflect
ES2015.Symbol
ES2015.Symbol.WellKnown
ES2016.Array.Include
ES2017.object
ES2017.Intl
ES2017.SharedMemory
ES2017.String
ES2017.TypedArrays
ES2018.Intl
ES2018.Promise
ES2018.RegExp
ESNext.AsyncIterable
ESNext.Array
ESNext.Intl
ESNext.Symbol

Note: If —lib is not specified a default list of libraries are injected. The default libraries injected are:
► For —target ES5: DOM,ES5,ScriptHost
► For —target ES6: DOM,ES6,DOM.Iterable,ScriptHost
—listEmittedFilesbooleanfalsePrint names of generated files part of the compilation.
—listFilesbooleanfalsePrint names of files part of the compilation.
—localestring(platform specific)The locale to use to show error messages, e.g. en-us.
Possible values are:
► English (US): en
► Czech: cs
► German: de
► Spanish: es
► French: fr
► Italian: it
► Japanese: ja
► Korean: ko
► Polish: pl
► Portuguese(Brazil): pt-BR
► Russian: ru
► Turkish: tr
► Simplified Chinese: zh-CN
► Traditional Chinese: zh-TW
—mapRootstringSpecifies the location where debugger should locate map files instead of generated locations. Use this flag if the .map files will be located at run-time in a different location than the .js files. The location specified will be embedded in the sourceMap to direct the debugger where the map files will be located. This flag will not create the specified path and generate the map files in that location. Instead, create a post build step that moves the files to the specified path.
—maxNodeModuleJsDepthnumber0The maximum dependency depth to search under node_modules and load JavaScript files. Only applicable with —allowJs.
—module
-m
stringtarget === “ES3” or “ES5” ? “CommonJS” : “ES6”Specify module code generation: “None”, “CommonJS”, “AMD”, “System”, “UMD”, “ES6”, “ES2015” or “ESNext”.
► Only “AMD” and “System” can be used in conjunction with —outFile.
“ES6” and “ES2015” values may be used when targeting “ES5” or lower.
—moduleResolutionstringmodule === “AMD” or “UMD” or “System” or “ES6” ? “Classic” : “Node”Determine how modules get resolved. Either “Node” for Node.js/io.js style resolution, or “Classic”. See Module Resolution documentation for more details.
—newLinestring(platform specific)Use the specified end of line sequence to be used when emitting files: “crlf” (windows) or “lf” (unix).”
—noEmitbooleanfalseDo not emit outputs.
—noEmitHelpersbooleanfalseDo not generate custom helper functions like extends in compiled output.
—noEmitOnErrorbooleanfalseDo not emit outputs if any errors were reported.
—noErrorTruncationbooleanfalseDo not truncate error messages.
—noFallthroughCasesInSwitchbooleanfalseReport errors for fallthrough cases in switch statement.
—noImplicitAnybooleanfalseRaise error on expressions and declarations with an implied any type.
—noImplicitReturnsbooleanfalseReport an error when not all code paths in function return a value.
—noImplicitThisbooleanfalseRaise error on this expressions with an implied any type.
—noImplicitUseStrictbooleanfalseDo not emit “use strict” directives in module output.
—noLibbooleanfalseDo not include the default library file (lib.d.ts).
—noResolvebooleanfalseDo not add triple-slash references or module import targets to the list of compiled files.
—noStrictGenericChecksbooleanfalseDisable strict checking of generic signatures in function types.
—noUnusedLocalsbooleanfalseReport errors on unused locals.
—noUnusedParametersbooleanfalseReport errors on unused parameters.
—outstringDEPRECATED. Use —outFile instead.
—outDirstringRedirect output structure to the directory.
—outFilestringConcatenate and emit output to single file. The order of concatenation is determined by the list of files passed to the compiler on the command line along with triple-slash references and imports. See output file order documentation for more details.
paths[2]ObjectList of path mapping entries for module names to locations relative to the baseUrl. See Module Resolution documentation for more details.
—preserveConstEnumsbooleanfalseDo not erase const enum declarations in generated code. See const enums documentation for more details.
—preserveSymlinksbooleanfalseDo not resolve symlinks to their real path; treat a symlinked file like a real one.
—preserveWatchOutputbooleanfalseKeep outdated console output in watch mode instead of clearing the screen
—prettybooleantrue unless piping to another program or redirecting output to a fileStylize errors and messages using color and context.
—project
-p
stringCompile a project given a valid configuration file.
The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a tsconfig.json file.
See tsconfig.json documentation for more details.
—reactNamespacestring“React”DEPRECATED. Use —jsxFactory instead.
Specifies the object invoked for createElement and spread when targeting “react” JSX emit.
—removeCommentsbooleanfalseRemove all comments except copy-right header comments beginning with /!
—resolveJsonModulebooleanfalseInclude modules imported with .json extension.
—rootDirstring(common root directory is computed from the list of input files)Specifies the root directory of input files. Only use to control the output directory structure with —outDir.
rootDirs[2]string[]List of root folders whose combined content represent the structure of the project at runtime. See Module Resolution documentation for more details.
—showConfigbooleanfalseRather than actually execute a build with the other input options and config files, show the final implied config file in the output.
—skipDefaultLibCheckbooleanfalseDEPRECATED. Use —skipLibCheck instead.
Skip type checking of default library declaration files.
—skipLibCheckbooleanfalseSkip type checking of all declaration files (.d.ts).
—sourceMapbooleanfalseGenerates corresponding .map file.
—sourceRootstringSpecifies the location where debugger should locate TypeScript files instead of source locations. Use this flag if the sources will be located at run-time in a different location than that at design-time. The location specified will be embedded in the sourceMap to direct the debugger where the source files will be located.
—strictbooleanfalseEnable all strict type checking options.
Enabling —strict enables —noImplicitAny, —noImplicitThis, —alwaysStrict, —strictBindCallApply, —strictNullChecks, —strictFunctionTypes and —strictPropertyInitialization.
—strictBindCallApplybooleanfalseEnable stricter checking of the bind, call, and apply methods on functions.
—strictFunctionTypesbooleanfalseDisable bivariant parameter checking for function types.
—strictPropertyInitializationbooleanfalseEnsure non-undefined class properties are initialized in the constructor. This option requires —strictNullChecks be enabled in order to take effect.
—strictNullChecksbooleanfalseIn strict null checking mode, the null and undefined values are not in the domain of every type and are only assignable to themselves and any (the one exception being that undefined is also assignable to void).
—suppressExcessPropertyErrorsbooleanfalseSuppress excess property checks for object literals.
—suppressImplicitAnyIndexErrorsbooleanfalseSuppress —noImplicitAny errors for indexing objects lacking index signatures. See issue #1232 for more details.
—target
-t
string“ES3”Specify ECMAScript target version:
“ES3” (default)
“ES5”
“ES6”/“ES2015”
“ES2016”
“ES2017”
“ES2018”
“ES2019”
“ES2020”
“ESNext”

Note: “ESNext” targets latest supported ES proposed features.
—traceResolutionbooleanfalseReport module resolution log messages.
—tsBuildInfoFilestring.tsbuildinfoSpecify what file to store incremental build information in.
—typesstring[]List of names of type definitions to include. See @types, —typeRoots and —types for more details.
—typeRootsstring[]List of folders to include type definitions from. See @types, —typeRoots and —types for more details.
—useDefineForClassFieldsbooleanfalseEmit class fields with ECMAScript-standard semantics.
—version
-v
Print the compiler’s version.
—watch
-w
Run the compiler in watch mode. Watch input files and trigger recompilation on changes. The implementation of watching files and directories can be configured using environment variable. See configuring watch for more details.
  • [1] These options are experimental.
  • [2] These options are only allowed in tsconfig.json, and not through command-line switches.

Related