TypeScript Complete Reference Index
Select any item below to open its full syntax specification, parameters, and live example.
TypeScript Syntax and Type Operators
! — definite assignment assertionclass Cache { value!: string; }
A definite assignment assertion on a declaration tells the checker to accept a binding or field even without ordinary initialization evidence. It is useful when initialization is guaranteed by an external mechanism, but it does not assign a runtime value. In an ES2022 class, an uninitialized field can still contain undefined. This declaration-site assertion is distinct from postfix ! on a value expression.
Example output: "undefined". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.
! — non-null assertion expressionconst length = maybe!.length;
Postfix ! removes null and undefined from the static type of an expression. It emits no runtime check. If the expression is actually nullish, subsequent property access may throw. Prefer an explicit guard when absence is possible; use an assertion only when an independently established invariant justifies it. This is not the prefix logical negation operator.
Example output: "3". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.
? — optional object propertytype Settings = { label?: string };
The question mark permits an object property to be absent. A read can yield undefined under strict null checking, so consumers must handle that possibility. With exactOptionalPropertyTypes enabled, explicitly writing undefined requires the declared property type to permit it; omission and undefined assignment are distinct. The modifier does not create a property at runtime.
Example output: "default". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.
TypeScript Compiler Options
--all — TypeScript CLItsc --help --all
Requests the expanded local option help, including categories and accepted values. This is especially useful when online documentation describes a newer compiler. It is not a request to enable all options. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
--build — TypeScript build commandtsc --build [project ...]
Selects build orchestration (alias -b): reads project references, orders dependencies, checks freshness and builds as needed. In 5.8.3 build mode can continue after upstream errors unless stopBuildOnErrors is enabled. Does not replace runtime package resolution. Baseline: TypeScript 5.8.3. Default: false (ordinary compilation mode). Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. Both projects build; running the app prints 8.
--clean — TypeScript build commandtsc --build --clean
Deletes compiler-known outputs for selected projects and referenced dependencies. Use dry clean first in unfamiliar workspaces; it is not a general directory deletion or a guarantee of removing obsolete artifacts. The example operates only on isolated generated outputs. Baseline: TypeScript 5.8.3. Default: false. Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. Generated JavaScript, declarations and build info are removed; original sources remain.
--dry — TypeScript build commandtsc --build --dry
Reports planned build actions without producing build outputs. It also supports dry clean. A dry run does not validate the source program or prove a later real build will succeed. Baseline: TypeScript 5.8.3. Default: false. Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. The log reports which projects would build; no generated project output is created.
--force — TypeScript build commandtsc --build --force
Treats selected projects as out of date even when previous outputs are current. Useful for controlled rebuilds; not equivalent to cleaning every artifact or dependency cache. Baseline: TypeScript 5.8.3. Default: false. Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. Verbose output reports that projects are being forcibly rebuilt.
--help — TypeScript CLItsc --help | tsc -h
Prints a compact CLI guide with common invocations and options, then exits without compiling. Use --help --all for the expanded option list. The tested help command does not create JavaScript even when a project exists. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
--init — TypeScript CLItsc --init
Creates a starter tsconfig.json in the current directory. The generated defaults and comments depend on compiler version; 5.8.3 generates a commented template with strict mode and ES2016 target. Review the settings for the intended host. A second initialization refuses to replace an existing config (TS5054). In 5.8.3 this diagnostic is printed with exit status zero; inspect the diagnostic and file, not just the exit status. It does not install dependencies or compile a program. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
--listFilesOnly — TypeScript CLItsc -p . --listFilesOnly
Lists the compiler program file names and stops before ordinary semantic checking and emission. Includes transitive imports and library declarations, not just configured roots. An incompatible assignment in the tested project is not reported by this mode; normal checking detects TS2322. In contrast, --listFiles reports files during compilation and can still emit output. Do not treat successful listing as successful type checking. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
--locale — TypeScript CLItsc --locale <language-tag> --pretty false
Changes compiler message language without changing type semantics or generated program output. The language is selected on the command line or by the host, not compilerOptions. In 5.8.3 Japanese and English diagnostics retain TS2322 for the same invalid assignment. Unsupported well-formed language tags may fall back to English; this is not a translation of source or types. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
--project — TypeScript CLItsc --project <directory-or-config-file> | tsc -p <path>
Selects a specific configuration rather than the implicit configuration discovered from the current working directory. Supply either a directory containing tsconfig.json or a JSON configuration file. Input files are selected by that configuration; explicit source file arguments cannot be combined with --project (TS5042). For building reference graphs use --build. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
--showConfig — TypeScript CLItsc -p . --showConfig
Prints the effective configuration as JSON rather than compiling. Useful for investigating inherited options, command-line overrides, computed strict-family settings and root file selection. The result is not the complete transitive file graph or proof of type correctness. Paths and serialization can vary by version and project layout. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
--stopBuildOnErrors — TypeScript build commandtsc --build --stopBuildOnErrors
Skips building downstream projects when an upstream project has errors. In 5.8.3 build mode otherwise continues on a best-effort basis. This flag does not itself prevent erroneous upstream JavaScript emission; use noEmitOnError where needed. Baseline: TypeScript 5.8.3. Default: false. Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. Expect TS2322 and a nonzero exit; upstream output exists but downstream JavaScript and declarations do not.
--verbose — TypeScript build commandtsc --build --verbose
Reports build planning, freshness decisions and projects being built. Use with --build; log wording is version-specific and not a stable machine interface. Baseline: TypeScript 5.8.3. Default: false. Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. The second run reports the projects are up to date.
--version — TypeScript CLItsc --version | tsc -v
Reports the compiler version selected by the command invocation, not the Node.js version or every installed TypeScript package. In a real project use the intended local executable or package script to avoid accidentally inspecting a global installation. Baseline: TypeScript 5.8.3. Commands are run with the pinned local compiler in an isolated directory; omit file labels. CLI-only setting.
TypeScript Advanced Declaration Authoring
.d.cts declaration format and generation.cts → .cjs + .d.cts
An explicit .cts source extension fixes the module format and declaration extension under NodeNext. The producer emits a matching JavaScript file and declaration; an independent consumer resolves the package output, not the source. The negative test checks argument compatibility using that generated declaration. Baseline: TypeScript 5.8.3, strict NodeNext consumer unless otherwise noted. Create the labeled files separately; do not paste this project into a single-file editor.
.d.mts declaration format and generation.mts → .mjs + .d.mts
An explicit .mts source extension fixes the module format and declaration extension under NodeNext. The producer emits a matching JavaScript file and declaration; an independent consumer resolves the package output, not the source. The negative test checks argument compatibility using that generated declaration. Baseline: TypeScript 5.8.3, strict NodeNext consumer unless otherwise noted. Create the labeled files separately; do not paste this project into a single-file editor.
TypeScript Syntax
Showing 20 of 480 entries