Tutorials  /  JavaScript

How To Set Up a New TypeScript Project

Ccentron Redaktion · January 2025 ·4 min read ·JavaScript, Tutorial

Introduction

You may have worked with TypeScript before when using a starter project or a tool like the Angular CLI. In this tutorial, you will learn how to set up a project without a starter’s help. You will also learn how compiling works in TypeScript and how to use a linter with your TypeScript project.

Deploy your frontend applications from GitHub using DigitalOcean App Platform. Let DigitalOcean focus on scaling your app.

VM

Matching infrastructure at centron

Node applications need somewhere to run: ccloud³ VMs with full root access from €3.12 per month – or as a managed server if you would rather not run it yourself. Rent a cloud server →

Table of Contents

  • Starting the TypeScript Project
  • Compiling the Project
  • Use Google TypeScript Style to Lint and Code

Prerequisites

To complete this tutorial, you will need the following:

  • The latest version of Node installed on your machine. Follow the How to Install Node.js and Create a Local Development Environment tutorial.
  • Familiarity with npm. To learn more, check out the How To Use Node.js Modules with npm and package.json tutorial.
  • A recent version of Ubuntu (20.04, 22.04, or 24.04). Upgrade older versions as needed.

Step 1 — Starting the TypeScript Project

Create a directory for your project:

Code
mkdir typescript-project

Change into your project directory:

Code
cd typescript-project

Install TypeScript as a development dependency:

Code
npm i typescript --save-dev

Initialize your project:

Code
npx tsc --init

This creates a tsconfig.json file in your project directory. Customize it as needed, such as by setting outDir to "./build" to organize compiled files.

Step 2 — Compiling the TypeScript Project

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

JavaScript

      const world = 'world';
      export function hello(who: string = world): string {
        return `Hello ${who}! `;
      }
    

Compile your project:

Code
npx tsc

Run the compiler in watch mode to automate recompilation:

Code
npx tsc -w

Step 3 — Using Google TypeScript Style to Lint and Correct Your Code

Install Google TypeScript Style (GTS):

Code
npm i gts --save-dev

Initialize GTS:

Code
npx gts init

Run lint checks and compile your code using GTS:

Code
npm run check
Code
npm run compile

Extend default ESLint rules by creating a file named .eslintrc:

YAML

      ---
      extends:
        - './node_modules/gts'
    

Conclusion for TypeScript Project

In this tutorial, you set up a project, customized its configuration, and integrated Google TypeScript Style. GTS simplifies project setup and ensures consistency with default linting and formatting rules.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie JavaScript
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren