Table of contents

  1. 1. Video Tutorial
  2. 2. Use JavaScript Libraries

It is possible to use regular JavaScript code in a TypeScript application. TypeScript is a superset of JavaScript, which means that any valid JavaScript code is also valid TypeScript code. This allows developers to gradually adopt TypeScript by starting with their existing JavaScript codebase and gradually migrating it to TypeScript. Additionally, developers can use legacy JavaScript libraries and frameworks in a TypeScript application without any issues.

Video Tutorial

The following tutorial shows you how to learn TypeScript step by step by importing your JavaScript code into a TypeScript project.

Use JavaScript Libraries

When working with legacy JavaScript code, you may encounter cases where you need to use a global variable that was previously injected by JavaScript code. In such situations, TypeScript offers a solution through the use of the special keyword declare. This keyword allows for declaring types for your existing JavaScript code and libraries to utilize them within your TypeScript codebase. However, it’s important to keep in mind that even though TypeScript offers additional type checking and other features, the final code will still be compiled to JavaScript and executed within a JavaScript runtime environment.


declare function myGlobalLegacyFunction(input: number): void;


Though not recommended practice, you can also declare external namespaces with any:

declare const myNamespace: any;