tsc CLI Options
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.
# Run a compile based on a backwards look through the fs for a tsconfig.json tsc # Emit JS for just the index.ts with the compiler defaults tsc index.ts # Emit JS for any .ts files in the folder src, with the default settings tsc src/*.ts # Emit files referenced in with the compiler settings from tsconfig.production.json tsc --project tsconfig.production.json # Emit d.ts files for a js file with showing compiler options which are booleans tsc index.js --declaration --emitDeclarationOnly # Emit a single .js file from two files via compiler options which take string arguments tsc app.ts util.ts --target esnext --outfile index.js
Compiler Options
If you’re looking for more information about the compiler options in a tsconfig, check out the TSConfig Reference
CLI Commands
Flag | Type | |
---|---|---|
--all |
|
|
Show all compiler options. |
||
--generateTrace |
|
|
Generates an event trace and a list of types. |
||
--help |
|
|
Gives local information for help on the CLI. |
||
--init |
|
|
Initializes a TypeScript project and creates a tsconfig.json file. |
||
--listFilesOnly |
|
|
Print names of files that are part of the compilation and then stop processing. |
||
--locale |
|
|
Set the language of the messaging from TypeScript. This does not affect emit. |
||
--project |
|
|
Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'. |
||
--showConfig |
|
|
Print the final configuration instead of building. |
||
--version |
|
|
Print the compiler's version. |
Build Options
Flag | Type | |
---|---|---|
--build |
|
|
Build one or more projects and their dependencies, if out of date |
||
--clean |
|
|
Delete the outputs of all projects. |
||
--dry |
|
|
Show what would be built (or deleted, if specified with '--clean') |
||
--force |
|
|
Build all projects, including those that appear to be up to date. |
||
--verbose |
|
|
Enable verbose logging. |
Watch Options
Flag | Type | |
---|---|---|
--excludeDirectories |
|
|
Remove a list of directories from the watch process. |
||
--excludeFiles |
|
|
Remove a list of files from the watch mode's processing. |
||
--fallbackPolling |
|
|
Specify what approach the watcher should use if the system runs out of native file watchers. |
||
--synchronousWatchDirectory |
|
|
Synchronously call callbacks and update the state of directory watchers on platforms that don`t support recursive watching natively. |
||
--watch |
|
|
Watch input files. |
||
--watchDirectory |
|
|
Specify how directories are watched on systems that lack recursive file-watching functionality. |
||
--watchFile |
|
|
Specify how the TypeScript watch mode works. |
Compiler Flags
Flag | Type | Default |
---|---|---|
--allowJs |
|
|
Allow JavaScript files to be a part of your program. Use the |
||
--allowSyntheticDefaultImports |
|
|
Allow 'import x from y' when a module doesn't have a default export. |
||
--allowUmdGlobalAccess |
|
|
Allow accessing UMD globals from modules. |
||
--allowUnreachableCode |
|
|
Disable error reporting for unreachable code. |
||
--allowUnusedLabels |
|
|
Disable error reporting for unused labels. |
||
--alwaysStrict |
|
|
Ensure 'use strict' is always emitted. |
||
--assumeChangesOnlyAffectDirectDependencies |
|
|
Have recompiles in projects that use |
||
--baseUrl |
|
|
Specify the base directory to resolve non-relative module names. |
||
--charset |
|
|
No longer supported. In early versions, manually set the text encoding for reading files. |
||
--checkJs |
|
|
Enable error reporting in type-checked JavaScript files. |
||
--composite |
|
|
Enable constraints that allow a TypeScript project to be used with project references. |
||
--declaration |
|
|
Generate .d.ts files from TypeScript and JavaScript files in your project. |
||
--declarationDir |
|
|
Specify the output directory for generated declaration files. |
||
--declarationMap |
|
|
Create sourcemaps for d.ts files. |
||
--diagnostics |
|
|
Output compiler performance information after building. |
||
--disableReferencedProjectLoad |
|
|
Reduce the number of projects loaded automatically by TypeScript. |
||
--disableSizeLimit |
|
|
Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server. |
||
--disableSolutionSearching |
|
|
Opt a project out of multi-project reference checking when editing. |
||
--disableSourceOfProjectReferenceRedirect |
|
|
Disable preferring source files instead of declaration files when referencing composite projects. |
||
--downlevelIteration |
|
|
Emit more compliant, but verbose and less performant JavaScript for iteration. |
||
--emitBOM |
|
|
Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. |
||
--emitDeclarationOnly |
|
|
Only output d.ts files and not JavaScript files. |
||
--emitDecoratorMetadata |
|
|
Emit design-type metadata for decorated declarations in source files. |
||
--esModuleInterop |
|
|
Emit additional JavaScript to ease support for importing CommonJS modules. This enables |
||
--exactOptionalPropertyTypes |
|
|
Interpret optional property types as written, rather than adding |
||
--experimentalDecorators |
|
|
Enable experimental support for TC39 stage 2 draft decorators. |
||
--explainFiles |
|
|
Print files read during the compilation including why it was included. |
||
--extendedDiagnostics |
|
|
Output more detailed compiler performance information after building. |
||
--forceConsistentCasingInFileNames |
|
|
Ensure that casing is correct in imports. |
||
--generateCpuProfile |
|
|
Emit a v8 CPU profile of the compiler run for debugging. |
||
--importHelpers |
|
|
Allow importing helper functions from tslib once per project, instead of including them per-file. |
||
--importsNotUsedAsValues |
|
|
Specify emit/checking behavior for imports that are only used for types. |
||
--incremental |
|
|
Save .tsbuildinfo files to allow for incremental compilation of projects. |
||
--inlineSourceMap |
|
|
Include sourcemap files inside the emitted JavaScript. |
||
--inlineSources |
|
|
Include source code in the sourcemaps inside the emitted JavaScript. |
||
--isolatedModules |
|
|
Ensure that each file can be safely transpiled without relying on other imports. |
||
--jsx |
|
|
Specify what JSX code is generated. |
||
--jsxFactory |
|
|
Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. |
||
--jsxFragmentFactory |
|
|
Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. |
||
--jsxImportSource |
|
|
Specify module specifier used to import the JSX factory functions when using |
||
--keyofStringsOnly |
|
|
Make keyof only return strings instead of string, numbers or symbols. Legacy option. |
||
--lib |
|
|
Specify a set of bundled library declaration files that describe the target runtime environment. |
||
--listEmittedFiles |
|
|
Print the names of emitted files after a compilation. |
||
--listFiles |
|
|
Print all of the files read during the compilation. |
||
--mapRoot |
|
|
Specify the location where debugger should locate map files instead of generated locations. |
||
--maxNodeModuleJsDepth |
|
|
Specify the maximum folder depth used for checking JavaScript files from |
||
--module |
|
|
Specify what module code is generated. |
||
--moduleResolution |
|
|
Specify how TypeScript looks up a file from a given module specifier. |
||
--newLine |
|
Platform specific. |
Set the newline character for emitting files. |
||
--noEmit |
|
|
Disable emitting files from a compilation. |
||
--noEmitHelpers |
|
|
Disable generating custom helper functions like |
||
--noEmitOnError |
|
|
Disable emitting files if any type checking errors are reported. |
||
--noErrorTruncation |
|
|
Disable truncating types in error messages. |
||
--noFallthroughCasesInSwitch |
|
|
Enable error reporting for fallthrough cases in switch statements. |
||
--noImplicitAny |
|
|
Enable error reporting for expressions and declarations with an implied |
||
--noImplicitOverride |
|
|
Ensure overriding members in derived classes are marked with an override modifier. |
||
--noImplicitReturns |
|
|
Enable error reporting for codepaths that do not explicitly return in a function. |
||
--noImplicitThis |
|
|
Enable error reporting when |
||
--noImplicitUseStrict |
|
|
Disable adding 'use strict' directives in emitted JavaScript files. |
||
--noLib |
|
|
Disable including any library files, including the default lib.d.ts. |
||
--noPropertyAccessFromIndexSignature |
|
|
Enforces using indexed accessors for keys declared using an indexed type. |
||
--noResolve |
|
|
Disallow |
||
--noStrictGenericChecks |
|
|
Disable strict checking of generic signatures in function types. |
||
--noUncheckedIndexedAccess |
|
|
Add |
||
--noUnusedLocals |
|
|
Enable error reporting when local variables aren't read. |
||
--noUnusedParameters |
|
|
Raise an error when a function parameter isn't read. |
||
--out |
|
|
Deprecated setting. Use |
||
--outDir |
|
|
Specify an output folder for all emitted files. |
||
--outFile |
|
|
Specify a file that bundles all outputs into one JavaScript file. If |
||
--paths |
|
|
Specify a set of entries that re-map imports to additional lookup locations. |
||
--plugins |
|
|
Specify a list of language service plugins to include. |
||
--preserveConstEnums |
|
|
Disable erasing |
||
--preserveSymlinks |
|
|
Disable resolving symlinks to their realpath. This correlates to the same flag in node. |
||
--preserveValueImports |
|
|
Preserve unused imported values in the JavaScript output that would otherwise be removed. |
||
--preserveWatchOutput |
|
|
Disable wiping the console in watch mode. |
||
--pretty |
|
|
Enable color and formatting in TypeScript's output to make compiler errors easier to read. |
||
--reactNamespace |
|
|
Specify the object invoked for |
||
--removeComments |
|
|
Disable emitting comments. |
||
--resolveJsonModule |
|
|
Enable importing .json files. |
||
--rootDir |
|
Computed from the list of input files. |
Specify the root folder within your source files. |
||
--rootDirs |
|
Computed from the list of input files. |
Allow multiple folders to be treated as one when resolving modules. |
||
--skipDefaultLibCheck |
|
|
Skip type checking .d.ts files that are included with TypeScript. |
||
--skipLibCheck |
|
|
Skip type checking all .d.ts files. |
||
--sourceMap |
|
|
Create source map files for emitted JavaScript files. |
||
--sourceRoot |
|
|
Specify the root path for debuggers to find the reference source code. |
||
--strict |
|
|
Enable all strict type-checking options. |
||
--strictBindCallApply |
|
|
Check that the arguments for |
||
--strictFunctionTypes |
|
|
When assigning functions, check to ensure parameters and the return values are subtype-compatible. |
||
--strictNullChecks |
|
|
When type checking, take into account |
||
--strictPropertyInitialization |
|
|
Check for class properties that are declared but not set in the constructor. |
||
--stripInternal |
|
|
Disable emitting declarations that have |
||
--suppressExcessPropertyErrors |
|
|
Disable reporting of excess property errors during the creation of object literals. |
||
--suppressImplicitAnyIndexErrors |
|
|
Suppress |
||
--target |
|
|
Set the JavaScript language version for emitted JavaScript and include compatible library declarations. |
||
--traceResolution |
|
|
Log paths used during the |
||
--tsBuildInfoFile |
|
|
Specify the folder for .tsbuildinfo incremental compilation files. |
||
--typeRoots |
|
|
Specify multiple folders that act like |
||
--types |
|
|
Specify type package names to be included without being referenced in a source file. |
||
--useDefineForClassFields |
|
|
Emit ECMAScript-standard-compliant class fields. |
||
--useUnknownInCatchVariables |
|
|
Default catch clause variables as |
Related
- Every option is fully explained in the TSConfig Reference.
- Learn how to use a
tsconfig.json
files. - Learn how to work in an MSBuild project.
© 2012-2022 Microsoft
Licensed under the Apache License, Version 2.0.
https://www.typescriptlang.org/docs/handbook/compiler-options.html