← 返回命令列表

Linux command

tsc 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Compile a TypeScript file

tsc [file.ts]

Compile using a tsconfig.json

tsc -p [tsconfig.json]

Compile in watch mode

tsc -w

Compile with strict mode

tsc --strict [file.ts]

Compile to a specific ECMAScript

tsc --target [ES2020] [file.ts]

Output to a specific directory

tsc --outDir [dist] [file.ts]

Generate source maps

tsc --sourceMap [file.ts]

Initialize a new tsconfig.json

tsc --init

说明

tsc is the TypeScript compiler that transforms TypeScript (.ts, .tsx) files into JavaScript (.js). Developed by Microsoft, TypeScript is a superset of JavaScript that adds optional static typing and modern language features. When run without arguments in a directory with tsconfig.json, tsc compiles the project according to that configuration. When files are specified on the command line, tsconfig.json is ignored unless -p is used. The compiler performs type checking to catch errors during development, then emits valid JavaScript. The --strict flag enables comprehensive type checking including strict null checks and no implicit any. Watch mode (-w) monitors source files and recompiles automatically when changes are detected, enabling a fast development workflow.

参数

-p, --project _path_
Compile project from tsconfig.json at path
-w, --watch
Watch input files and recompile on changes
-t, --target _version_
ECMAScript target version (ES5, ES2015, ES2020, ES2022, ESNext)
--outDir _directory_
Redirect output to specified directory
--outFile _file_
Concatenate and emit output to single file
--strict
Enable all strict type-checking options
--noEmit
Do not emit outputs; type-check only
--sourceMap
Generate corresponding .map source map files
--declaration
Generate .d.ts declaration files
--module _system_
Module system: commonjs, es2015, es2020, esnext, node16, nodenext
--moduleResolution _strategy_
Module resolution strategy: node, nodenext, bundler
--incremental
Enable incremental compilation for faster rebuilds
--skipLibCheck
Skip type checking of declaration files
--esModuleInterop
Enable interoperability between CommonJS and ES Modules
--resolveJsonModule
Allow importing .json files
--jsx _mode_
JSX handling: react, react-jsx, react-jsxdev, preserve
--lib _libs_
Specify library files to include (e.g., ES2020, DOM, ES2020.Promise)
--noEmitOnError
Do not emit outputs if any errors are reported
--init
Initialize a tsconfig.json file
--listFiles
Print names of files that are part of the compilation
--showConfig
Print the final resolved configuration instead of compiling
-h, --help
Show help
-v, --version
Show version

FAQ

What is the tsc command used for?

tsc is the TypeScript compiler that transforms TypeScript (.ts, .tsx) files into JavaScript (.js). Developed by Microsoft, TypeScript is a superset of JavaScript that adds optional static typing and modern language features. When run without arguments in a directory with tsconfig.json, tsc compiles the project according to that configuration. When files are specified on the command line, tsconfig.json is ignored unless -p is used. The compiler performs type checking to catch errors during development, then emits valid JavaScript. The --strict flag enables comprehensive type checking including strict null checks and no implicit any. Watch mode (-w) monitors source files and recompiles automatically when changes are detected, enabling a fast development workflow.

How do I run a basic tsc example?

Run `tsc [file.ts]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -p, --project _path_ do in tsc?

Compile project from tsconfig.json at path