.ts

What is a .ts file?

TypeScript Source File · Code and data · Microsoft · 2012

A .ts file is usually TypeScript source code: JavaScript with a type system that catches mistakes before the code runs. It is plain text compiled down to plain JavaScript for browsers and Node.js.

Category
Code and data
Type
Plain text
Is a .ts file safe to open? Caution. TypeScript is program source that runs once compiled. Review unfamiliar code before running it. A .ts that is actually a video is safe to play.

What is a .ts file used for?

TypeScript adds optional static types to JavaScript, so an editor can flag errors as you type and large codebases stay maintainable. The compiler (tsc) strips the types and outputs ordinary .js that runs anywhere JavaScript does.

Watch out for a naming clash: .ts is also the extension for an MPEG transport stream, a video format used in broadcasting and streaming. If your .ts will not open in an editor and is large and binary, it is video, not code.

What opens a .ts file?

The .ts format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.

Windows

  • VS Code
  • WebStorm
  • any text editor

macOS

  • VS Code
  • WebStorm
  • any text editor

Linux

  • VS Code
  • vim
  • any text editor

Open a .ts file step by step

  1. Confirm the file really is a .ts. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with VS Code or WebStorm.
  3. On Mac, use VS Code or WebStorm.
  4. On Linux, try VS Code or vim.
  5. Still stuck? Convert the .ts to js, which opens more widely.

Why can't I open my .ts file?

Almost always because no installed app understands TypeScript. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .ts at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

How to convert a .ts file

You can convert a .ts file to js using a conversion tool or the export menu of an app that opens it.

TypeScript has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

Frequently asked questions

What is a .ts file?

A .ts file is usually TypeScript source code: JavaScript with a type system that catches mistakes before the code runs. It is plain text compiled down to plain JavaScript for browsers and Node.js.

Is a .ts file TypeScript or a video?

Usually TypeScript source code. But .ts is also an MPEG transport stream video. A text editor opens code; a large binary that only plays in a media player is video.

How do I run a TypeScript file?

Compile it with tsc file.ts to produce JavaScript, then run that with Node, or use a runner like ts-node or Deno that executes TypeScript directly.

What is the difference between .ts and .js?

TypeScript (.ts) adds a type system on top of JavaScript (.js). The types are checked at compile time and removed, leaving plain JavaScript to run.

Related formats

Sources

Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.