What is MIME type "text/x-typescript"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

The MIME type text/x-typescript signifies that a file contains TypeScript code. It tells software, code editors, and web servers that the content needs to be handled as human-readable code rather than binary data.

Files using this MIME type typically end with TS. They are processed by compilers that convert TypeScript into JavaScript, which browsers can execute.

This MIME type helps in several ways:

For more on how TypeScript boosts JavaScript development, see the official TypeScript website.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/x-typescript    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/x-typescript">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/x-typescript');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

Can web browsers execute text/x-typescript files directly?

No, standard web browsers cannot execute TypeScript directly. Browsers only understand JavaScript; therefore, files served as text/x-typescript must be compiled (transpiled) into text/javascript using tools like the TypeScript Compiler (tsc) or bundlers like Webpack before deployment.

Why is my server identifying .ts files as video instead of code?

The .ts extension is historically shared with MPEG Transport Stream video files (video/mp2t). Many default server configurations (like IIS or old Apache setups) assume .ts is video. You must manually configure your server to map the extension to text/x-typescript to prevent MIME type mismatch errors.

How do I configure Nginx to serve TypeScript files correctly?

To serve .ts files as code, open your mime.types file (usually in /etc/nginx/) and add the line text/x-typescript ts;. If the extension is already mapped to video/mp2t, you must remove that mapping or overwrite it in your specific server block configuration.

What are the alternative MIME types for TypeScript?

While text/x-typescript is common, you may also encounter application/x-typescript or text/typescript. Since TypeScript is not an IANA standard MIME type yet, various tools use the x- prefix to indicate it is a non-standard or experimental subtype, though modern build tools generally recognize all variations.

How do I fix the 'Resource interpreted as Script but transferred with MIME type video/mp2t' error?

This console error happens when a browser attempts to load a TypeScript file (often a source map) but the server sends a video header. To fix this, update your web server's MIME type configuration to associate the TS extension with text/x-typescript or application/x-typescript.

Should I use text/x-typescript for production environments?

Generally, no. Production environments should serve compiled .js files with the text/javascript MIME type. The text/x-typescript type is primarily used during development, for serving source maps for debugging, or for documentation sites displaying raw code.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.