> For the complete documentation index, see [llms.txt](https://docs.bashschool.in/v1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bashschool.in/v1/javascript/typescript/the-tsc-compiler.md).

# The tsc Compiler

Let's set up a simple TypeScript Node.js application on your local machine. Follow these steps to get started:

**Step 1 - Install `tsc`/TypeScript Globally**

First, install TypeScript globally using npm.

```bash
npm install -g typescript
```

**Step 2 - Initialize a Node.js Project with TypeScript**

Create a new directory for your Node.js application and initialize it with TypeScript.

```bash
mkdir node-app
cd node-app
npm init -y
npx tsc --init
```

These commands will create your project directory and initialize it with `package.json` and `tsconfig.json`.

**Step 3 - Create a `a.ts` File**

Create a new TypeScript file named `a.ts` and add the following code:

```typescript
const x: number = 1;
console.log(x);
```

**Step 4 - Compile the `.ts` File to a `.js` File**

Use the TypeScript compiler to compile your TypeScript file into JavaScript.

```bash
tsc -b
```

**Step 5 - Check the Generated `a.js` File**

Open the generated `a.js` file. You'll see that it contains plain JavaScript code with no type annotations.

```javascript
var x = 1;
console.log(x);
```

**Step 6 - Modify `a.ts` to Assign `x` to a String**

Change `a.ts` by converting `const` to `let` and assigning `x` to a string:

```typescript
let x: number = 1;
x = "something other than number";  // This will cause a type error
console.log(x);
```

**Step 7 - Recompile the Code**

Compile the code again with the TypeScript compiler:

```bash
tsc -b
```

You will see errors in the console indicating type mismatches. Additionally, notice that no `a.js` file is generated this time due to the type errors.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bashschool.in/v1/javascript/typescript/the-tsc-compiler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
