Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript various file extensions explained?

In trying to understand TypeScript a little more, what are the relations between all of the file extensions?

  • TypeScript, *.ts
  • Definition, *.d.ts
  • Map, *.map
  • JavaScript, *.js
like image 972
David Pine Avatar asked May 06 '16 03:05

David Pine


1 Answers

I initially started entering the question above thinking to myself that someone would come along and help me out. Then I noticed an "answer your own question" option and I was inspired by Jeff Atwood's encouraging blog post - so I decided I should attempt to answer my own question. I had to do some research but now I have the understanding I was originally looking for.


  • TypeScript, *.ts

A typed superset of JavaScript that "compiles" to plain JavaScript. These files have the potential to utilize type-safety and strongly-typed syntax, with IDE intellisense.

  • Definition, *.d.ts

A *.d.ts file is used to provide TypeScript type information about an API that's written in JavaScript. Type definition files contain the defining types for all of the public APIs within a corresponding .js, for example - JQuery has jQuery.js without the jQuery.d.ts a TypeScript file consuming jQuery wouldn't know about its types, therefore intellisense is gone.

  • Map, *.map

A .map file is a source map file that let tools "map" between the emitted JavaScript code and the TypeScript source files that created it. This concept has been around since CoffeeScript.

  • JavaScript, *.js

According to MDN:

JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight language. Inside a host environment (for example, a web browser), JavaScript can be connected to the objects of its environment to provide programmatic control over them.

The relationship between a .ts file and a .js file is that a TypeScript file compiles down to a JavaScript file.

like image 153
David Pine Avatar answered Oct 03 '22 09:10

David Pine