.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.

How to open 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. For a step-by-step walkthrough, see how to open a .ts file.

Windows

  • VS Code
  • WebStorm
  • any text editor

macOS

  • VS Code
  • WebStorm
  • any text editor

Linux

  • VS Code
  • vim
  • any text editor

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.

.ts file signature (magic bytes)

Programs recognise a .ts file by the bytes at the start of the file, not by its name. These are the signatures for TypeScript.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

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: