Skip to content

About

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

4 watching

Forks

 
 

Repository files navigation

TypeScript

CI npm version Downloads OpenSSF Scorecard

TypeScript is a language for application-scale JavaScript. TypeScript adds optional types to JavaScript that support tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the playground, and stay up to date via our blog and Twitter account.

Find others who are using TypeScript at our community page.

Installing

For the latest stable version:

npm install -D typescript

For our nightly builds:

npm install -D typescript@next

Formatting

Run tsc --format to format project input files in place before checking and emitting them. Use tsc --formatOnly to format without type checking or emitting JavaScript or declarations. Both flags also work with tsc -b.

To check formatting without changing source files, add --formatDiagnostics to either mode:

tsc --formatOnly --formatDiagnostics

With --format, formatting diagnostics are included in the reported errors but do not block checking or JavaScript/declaration emit, even with --noEmitOnError. Ordinary compiler errors still follow the usual emit rules.

Set project formatting preferences in the top-level formattingOptions member of your config:

{
    "formattingOptions": {
        "indentSize": 4,
        "tabSize": 4,
        "convertTabsToSpaces": true,
        "insertSpaceAfterCommaDelimiter": true
    }
}

These settings inherit per property through extends and take priority over editor formatting preferences. Incremental projects keep formatting state separately from compilation state in their .tsbuildinfo, so formatting-only runs do not mark compilation outputs as current. Changing formatting preferences causes all project input files to be formatted again.

Parsing and formatting run in parallel unless --singleThreaded is set. Composite projects use their complete config-generated root file set directly. Non-composite projects discover additional input files through imports and references; default libraries and dependencies in node_modules (including linked packages) are not formatted.

With --formatOnly, append inclusive, one-based line ranges to individual input file names. Files without ranges are formatted in full:

tsc --formatOnly ./src/compiler/checker.ts:120-500,1001-2100 ./src/compiler/core.ts

Explicit formatting-only input files also use formatting preferences from a discovered config, or from a config selected with --project.

The JavaScript API exposes the same formatting checks through program.getFormattingDiagnostics(file?, spans?). It reads formattingOptions without writing source files or incremental state. Pass a source file, a file name/URI, or a list of files; omit the first argument to check all project formatting inputs. Optional spans use half-open { pos, end } UTF-16 offsets, and an empty span list checks nothing.

Contribute

There are many ways to contribute to TypeScript.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Documentation

Roadmap

For details on our planned features and future direction, please refer to our roadmap.

About

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages