What makes TypeScript unique is that it is completely written in TypeScript, with TypeScript accounting for 100

According to information on the TypeScript repository on GitHub, it consists of 100.0% TypeScript files (.ts)

https://i.sstatic.net/Is7XE.png

I am curious about how TypeScript is able to compile itself to JavaScript without any external help. Can you explain how this process works?

Answer №1

Compiler bootstrapping is a common practice with many benefits, one of which is that the language you are using to write the compiler is often best suited for understanding the concepts being implemented. Major languages like C and C++ have self-hosting compilers, meaning they can run a large amount of code through their own compiler to test functionality.

When creating a new language, it makes sense to take advantage of the benefits of that language while writing the compiler. While the very first pass may need to be written in an existing language, subsequent revisions can be compiled using the compiler itself. This may limit the features available to the compiler, but since you control the compiler, this is usually not a major issue.

For example, the C++ compiler clang was initially written in a subset of C++ that could be compiled by both g++ and Microsoft Visual C++.

Considering TypeScript is a superset of JavaScript, in theory, the compiler could be written in the shared syntax and compile under either language. Although this may not be the case here, the relationship between the two languages provides a strong foundation for building the initial compiler.

Answer №2

Here's something I find quite intriguing.

Git allows for a file called .gitattributes to be included in repositories. Github utilizes a tool known as linguist that leverages this file to provide language details for each repository. In the typescript repository, there exists a .gitattributes file with the following contents:

*.js linguist-language=TypeScript
* -text

If you were to fork the typescript repository, delete this file, commit the changes on Github, and patiently wait for their repository analysis job to finish, you would witness a shift in the language graph. https://i.sstatic.net/nqtzo.jpg

Answer №3

Typescript has the unique ability to host itself and store a Last-Known-Good (LKG) version for compiling future updates. As of today (01/15/2022), this version can be found in the lib directory.

Answer №4

The original ts to js transpiler was crafted using javascript (or theoretically, any other programming language could have been used). Once the initial transpiler was up and running, it enabled developers to create any program solely in typescript, including the transpiler itself.

Subsequently, the subsequent version of the transpiler could be developed in typescript. Therefore, starting from the second iteration, all subsequent versions of ts to js transpilers were coded in typescript.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Detect changes in class properties using Node.js

Is it feasible to establish direct proxy watchers for class properties in Node.js? class User{ constructor(name){ this.name = name; let pObject = new Proxy(this,{ set: () => { console.log("something cha ...

JavaScript: XHR struggles with managing multiple asynchronous requests

Hey there, I'm currently attempting to access a single resource multiple times with various parameters. Here's what I have so far: Essentially, I am making requests for the following domains: var domains = [ 'host1', 'host2&apos ...

Ensuring the selected date matches any consecutive dates within the dates array in Angular

Imagine if 01/01/2022 is chosen from the input field, and my array of dates looks something like this: ['31/12/2021', '01/11/2021', '02/01/2022'...] In this scenario, when '31/12/2021' and '02/01/2022' are ...

Maintain the structure of ajax POST requests and display a real-time feed of

I've been developing an openvz script to run virtual machines at home. I've been exploring JavaScript and AJAX functions to send post requests, which are then displayed in the innerHTML section of my webpage. However, I've encountered an iss ...

Ways to enforce TypeScript return type and prevent implicit casting

I am facing an issue with a method in my code that fetches data from an external API and returns it. The problem lies in the fact that the data type being returned is incorrect. The function's return type is IClickupTeam, but the actual data returned ...

The Ajax success callback unexpectedly displays the number "1" in the top left corner of the empty page instead of updating the specified div

Currently, I am in the process of developing a Yii2 application. I have encountered an issue where I select data from a Bootstrap modal popup and submit it to a controller action that contains an insert query. The problem arises after submitting the data f ...

vue mapGetters not fetching data synchronously

Utilizing vuex for state management in my application, I am implementing one-way binding with my form. <script> import { mapGetters } from 'vuex' import store from 'vuex-store' import DataWidget from '../../../../uiCo ...

Leveraging the `app.get()` method in Firebase cloud functions to retrieve and interact with files

I am currently integrating Firebase Hosting with Firebase Functions to restrict access to .html content only to users with a valid Firebase token. Within my iOS app, I can successfully send the token when accessing Firebase Hosting. The Cloud Function dec ...

The inputs for Node express middleware are unclear and lack definition

I am currently exploring Node.js as a potential replacement for my existing DOT NET API. I have created middleware to enforce basic non-role authorization in my application, but I am encountering compilation problems with the function inputs. Compilation ...

Reverse action on Angular checklist-model checkboxes

I have successfully implemented checklist-model.js for angular to select from a dynamically generated list of objects. However, I now need to create the functionality to move unchecked checkboxes into a new array (and remove them when checked again). Can a ...

Encountering AJAX Error 0 with jQueryUI Autocomplete upon pressing enter key

Currently, I am facing an issue with a search box that utilizes the jqueryUI .autocomplete feature to retrieve data through AJAX for providing suggestions. The problem arises when a user presses the enter key before the AJAX call to the source completes, r ...

Troubleshooting data binding issues with bootstrap tab panes and accordion components

Initially, I set up a bootstrap accordion that generates panels based on items with the property "gebieden". This functionality is functioning correctly. Within each panel, I implemented bootstrap 'tabs'. For every object with properties "onderw ...

Is it possible to transfer elements from one array to another when clicked, but without copying the contents to the new array objects?

Welcome, For my latest project, I am excited to create a "Learning Cards" App from scratch. The concept is pretty straightforward: it consists of cards with questions. Upon clicking a button, you can reveal the correct answer. Additionally, there's a ...

Manipulating the position of objects in Three.js using WebGL

Currently, I am exploring WebGl and Three.js to work on a project. Unfortunately, I seem to be encountering an issue regarding retrieving the position of a custom mesh that I created. Each time I attempt to obtain the position, I consistently receive value ...

What is the method for including a button column within a datagrid object?

I am looking to enhance my data grid object by adding a button column. The data table is filled in the aspx.cs file, and we are using the .Net Webform structure. Can anyone provide guidance on how to achieve this? Below is an example of my current grid s ...

I am looking to dynamically assign an href attribute to a link using a variable within my script. How can I achieve

I am working on displaying an image inside a jQuery slider with the following HTML markup:- <li> <figure> <a href="~/img/big.jpg" class="thumb"> <img src="~/img/small.jpg" alt=""/> <span> ...

Apply a CSS class once a TypeScript function evaluates to true

Is it possible to automatically apply a specific CSS class to my Div based on the return value of a function? <div class="{{doubleClick === true ? 'cell-select' : 'cell-deselect'}}"></div> The doubleClick function will ret ...

Having issues with the rotation algorithm for an array-based image representation

My goal is to rotate the image represented by matrix (a) by mapping the values in the "a" coordinates to the rotated image, as shown below. However, I am puzzled as to why this method fails to produce the desired result. a = [[1, 2, 3], [4, 5, 6], ...

Tips on preventing the opening of a new browser tab by using Ctrl + click

Hey there, I've got a list of products that can be selected using the Ctrl key. $(parentSelector).on("click", function (evnt) { evnt.stopImmediatePropagation(); var item = $(evnt.delegateTarget) ...

Ways to ensure a video completely fills the frame

I am experiencing an issue where the video in the main div of my home page does not fully fill the div right away - I have to refresh the page for this to happen. As a result, there is black space on the left and right sides. Interestingly enough, this pr ...