TypeScript
CLI Toolmicrosoft/TypeScript
TypeScript is a typed superset of JavaScript that compiles to clean JavaScript output.
Overview
TypeScript adds optional static types to JavaScript, enabling better tooling and error detection for large-scale applications. It compiles to readable, standards-based JavaScript that runs in any browser, host, or OS. Widely used by millions for building enterprise-grade software.
README Preview
# TypeScript\r\n\r\n\r\n\r\n[](https://github.com/microsoft/TypeScript/actions/workflows/ci.yml)\r\n[](https://www.npmjs.com/package/typescript)\r\n[](https://www.npmjs.com/package/typescript)\r\n[](https://securityscorecards.dev/viewer/?uri=github.com/microsoft/TypeScript)\r\n\r\n\r\n[TypeScript](https://www.typescriptlang.org/) 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](https://www.typescriptlang.org/play/), and stay up to date via [our blog](https://blogs.msdn.microsoft.com/typescript) and [Twitter account](https://twitter.com/typescript).\r\n\r\nFind others who are using TypeScript at [our community page](https://www.typescriptlang.org/community/).\r\n\r\n## Installing\r\n\r\nFor the latest stable version:\r\n\r\n```bash\r\nnpm install -D typescript\r\n```\r\n\r\nFor our nightly builds:\r\n\r\n```bash\r\nnpm install -D typescript@next\r\n```\r\n\r\n## Contribute\r\n\r\n**NOTE: Code changes in this repo are now limited to a small category of fixes**:\r\n\r\n * Crashes that were introduced in 5.9 or 6.0 that *also* repro in 7.0 *and* have a portable fix *and* don't incur other behavioral changes\r\n * Security issues\r\n * Language service crashes that substantially impact mainline usage\r\n * Serious regressions from 5.9 (these must *seriously* impact a *large* proportion of users)\r\n\r\nMost bug fixes should be submitted to the [typescript-go](https://github.com/microsoft/TypeScript-go) repository.\r\nFeature additions and behavioral changes are currently on pause until TypeScript 7.0 is completed.\r\n\r\nThere are many ways to [contribute](https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md) to TypeScript.\r\n* [Submit bugs](https://github.com/microsoft/TypeScript/issues) and help us verify fixes as they are
FAQ (5)
TroubleshootingWhy does tsc --incremental miss errors after changing a .d.ts file in node_modules (stale diagnostics)?
This is a regression in TypeScript 7.0.2 (worked in 6.0.3): incremental builds keep stale diagnostics when a declare global block inside a package's module declaration file changes, because the .tsbuildinfo cache is not invalidated. The incremental run reports no errors while a clean build reports them (e.g., TS2345).
Fixes and workarounds:
1. Upgrade to TypeScript 7.1+ — the bug is confirmed fixed in 7.1 nightly (npm i typescript@next).
2. If stuck on 7.0.x, delete the build info file before each run to force a full re-check: rm -f <path>.tsbuildinfo && tsc --noEmit --incremental --tsBuildInfoFile <path>.tsbuildinfo -p tsconfig.json.
3. Alternatively, verify types with a clean non-incremental run: tsc --noEmit -p tsconfig.json.
Note: this commonly affects type-test setups (e.g., Vitest/expect-webdriverio) that run tsc --noEmit --incremental against global type augmentations from packages in node_modules.
TroubleshootingWhy does TypeScript 7.0.2 incremental build emit stale .d.ts files when a global declaration file changes?
This is a known bug in TypeScript 7.0.2. With isolatedModules + declaration + incremental, when a global-scope file (e.g. declare global or @types/node) changes in the same run as source files, dependent files' .d.ts are not re-emitted, and the .tsbuildinfo incorrectly records them as up-to-date, so the stale output persists across builds.
The fix (microsoft/typescript-go#4665) will NOT be backported to 7.0.x — the team only backports critical security/stability fixes. Solutions:
1. Upgrade to TypeScript 7.1 (or nightly typescript@7.1.0-dev.20261011.1 or later): npm install typescript@next.
2. Workaround on 7.0.2: delete the .tsbuildinfo file (or run a clean build) whenever a dependency bump or edit touches global declarations, forcing a full re-emit of all declaration files.
TroubleshootingHow to fix TS2536 error when indexing an `as`-remapped mapped type with `Exclude<keyof T & string, ...>` in TypeScript 7.0 native (tsgo)?
This is a regression in the native TypeScript 7.0.2 compiler (tsgo); the same code compiles cleanly in TS 5.9.3 and 6.0.3. Workaround: index the mapped type by its own keyof instead of recomputing the remapped key set with Exclude. Extract the mapped type into an alias and use Map<T>[keyof Map<T>]:
type EntryPathMap<T> = {
[K in keyof T & string as K extends '_key' ? never : K]: [PathTuples<T[K]>] extends [never]
? never
: readonly [K, ...ChildPaths<T[K]>];
};
type PathTuples<T> = T extends object ? EntryPathMap<T>[keyof EntryPathMap<T>] : [];
keyof EntryPathMap<T> resolves to the same key set as Exclude<keyof T & string, '_key'> and is accepted by all compilers. Alternatively, pin TypeScript to 5.9.3 or 6.0.3 (@typescript/typescript6) until the native compiler regression is fixed.
TroubleshootingWhy does tsgo (TypeScript native LSP server) crash with 'panic: assignment to entry in nil map' on shutdown?
This is a race condition in the typescript-go LSP file watcher (lspwatcher.WatchFiles). The watcher releases its lock while installing a subscription; if Watcher.Close runs in between, it sets w.watches = nil, and the subsequent map assignment panics. It typically triggers when the client closes documents and shuts down while a background project snapshot update re-registers watches — i.e., when the client does NOT advertise dynamic workspace/didChangeWatchedFiles registration and the server uses its internal watcher. tsgo --lsp --stdio exits with status 2.
**Fix:** Update your TypeScript native preview (typescript@7.x / tsgo) to a build that includes the fix from microsoft/typescript-go#4845, which rechecks closed under the lock before publishing the subscription and returns the lspwatcher: closed error instead of panicking.
**Workarounds until you can upgrade:**
1. Have your LSP client advertise dynamic file-watch registration (workspace.didChangeWatchedFiles.dynamicRegistration: true) so the server uses client-managed watchers instead of the internal watcher that contains the race.
2. If building from source, patch internal/lsp/lspwatcher/lspwatcher.go (WatchFiles): after reacquiring w.mu, recheck w.closed; if closed, close the unpublished subscription and return the existing lspwatcher: closed error. Do not suppress the panic or disable the watcher.
TroubleshootingHow to fix "Cannot find name 'ClassMethodDecoratorFunction'" error with TypeScript 5.0 decorators?
This is a documentation bug in TypeScript 5.0.4's lib.decorators.d.ts: the example references ClassMethodDecoratorFunction, but that type was never shipped in the lib files (the example also contains invalid function syntax). Workaround: declare the type yourself in your project:
type ClassMethodDecoratorFunction<
This = unknown,
Value extends (this: This, ...args: any[]) => any = (this: This, ...args: any[]) => any
> = (
value: Value,
context: ClassMethodDecoratorContext<This, Value>
) => Value | void;
Then the bound-method example works:
const bound: ClassMethodDecoratorFunction = function (value, context) {
if (context.private) throw new TypeError("Not supported on private methods.");
context.addInitializer(function (this: any) {
this[context.name] = this[context.name].bind(this);
});
};
Notes: use a normal function expression (the shorthand in the official example is invalid syntax), and cast this to any (or use a mapped access) to avoid the implicit-any error on this[context.name]. Upgrading to a newer TypeScript version is also recommended, as the incorrect example in lib.decorators.d.ts was corrected after 5.0.x. A ready-made type is available in the community at ajvincent/es-membrane (ClassMethodDecoratorFunction.d.mts).