# v7

In this example, we will guide you through the steps to turn your project into a TypeScript project. After the guide has been completed, you will benefit from strong type checking and code completion.

{% hint style="warning" %}
Use this example **only** for version 7&#x20;
{% endhint %}

## Requirements

In this example, we will assume that you are familiar with TypeScript and that you have it installed. \
\
If this is not the case, simply run the following to get packages you will need in this Woodshop: `npm install --save-dev typescript tsc-watch`

To make it easy for you, we created our own typings to help you using our exposed tools using TypeScript. Until version 6 they were located in the DefintelyTyped GitHub repository. Starting from version 7, they are now directly integrated into our `forest-express-sequelize` and `forest-express-mongoose` packages. That being said, no additional package needs to be installed.

### Configuration

As for every TypeScript project, we need to create a configuration file. It helps the transpiler to know where to take the files from, and where to transpile them.\
\
To have a smooth migration into TypeScript, we will use the following configuration:

{% hint style="info" %}
Add this file at the root of your project.
{% endhint %}

{% tabs %}
{% tab title="SQL" %}
{% code title="tsconfig.json" %}

```javascript
{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "pretty": true,
    "sourceMap": false,
    "target": "es2017",
    "outDir": "./dist",
    "baseUrl": "./",
    "types" : ["node", "express", "forest-express-sequelize", "sequelize"],
    "allowJs": true
  },
  "include": ["./**/*", ".env"],
  "exclude": ["node_modules", "dist"]
}
```

{% endcode %}
{% endtab %}

{% tab title="MongoDB" %}
{% code title="tsconfig.json" %}

```javascript
{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "pretty": true,
    "sourceMap": false,
    "target": "es2017",
    "outDir": "./dist",
    "baseUrl": "./",
    "types" : ["node", "express", "forest-express-mongoose", "mongoose"],
    "allowJs": true
  },
  "include": ["./**/*", ".env"],
  "exclude": ["node_modules", "dist"]
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

This tells the transpiler to take every file using `.ts` or `.js` (see `allowJs` option) as an extension, and to transpile them into a `./dist` folder. This is where your transpiled files will be. This type of configuration allows you to translate your app into TypeScript in dribs and drabs. No need to translate every file at once, change only the files you are interested in.\
\
Now that your TypeScript transpiler is set, we need to update our `.package.json` with new scripts to fit with the new structure of our project.

{% code title="package.json" %}

```javascript
"scripts": {
  "start": "node ./dist/server.js",
  "build": "rm -rf ./dist && npm run compile && npm run cp-config",
  "dev": "tsc-watch --onSuccess \"node ./dist/server.js\"",
  "compile": "tsc",
  "lint": "eslint . -c .eslintrc.json --ext .ts",
  "cp-config": "cp .env ./dist/"
},
```

{% endcode %}

Note that the script `dev` is the script to use while developing. It will transpile your sources every time you perform a change, and it will refresh your server.\
\
Finally, let's install the mandatory typings for a newly generated project, run this from a command prompt:

{% tabs %}
{% tab title="SQL" %}

```javascript
npm install --save-dev @types/node @types/express @types/sequelize
```

{% endtab %}

{% tab title="MongoDB" %}

```javascript
npm install --save-dev @types/node @types/express @types/mongoose
```

{% endtab %}
{% endtabs %}

And that's it! \
\
You are now able to code using TypeScript in your app. Simply change the extension from `.js` to `.ts` , change some code, and your file will be automatically handled.

The following section of this documentation will guide you through the migration of your files from `.js` to `.ts`. If you are using Mongoose, please refer to the [Migrate Mongoose files](/woodshop/how-tos/translate-your-project-into-typescript/v7/migrate-mongoose-files.md) section, otherwise, you are using Sequelize, and then please refer to the [Migrate Sequelize files](/woodshop/how-tos/translate-your-project-into-typescript/v7/migrate-sequelize-files.md) section.


---

# Agent Instructions: 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.forestadmin.com/woodshop/how-tos/translate-your-project-into-typescript/v7.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.
