chapter seven

7 Using TypeScript and JavaScript in the same project

 

This chapter covers:

  • How to enjoy the TypeScript benefits when working with a JavaScript library
  • The role of type definition files
  • How to upgrade an existing JavaScript app to TypeScript

In this chapter, we’ll show how you can benefit from such TypeScript features as getting compilation errors and auto-complete even while using third-party libraries written in JavaScript. We’ll start by explaining the role of type definition files, and then will discuss a concrete use case where an app written in TypeScript uses a JavaScript library. Finally, we’ll go over the things to consider for implementing the gradual upgrade of your app from JavaScript to TypeScript.

7.1  Type definition files

The JavaScript language was created in 1995, and gazillions lines of code were written in this language since then. Developers from around the globe have released thousands of libraries written in JavaScript, and the chances are that your TypeScript app could also benefit from using one of these libraries.

7.1.1  Getting familiar with type definition files

7.1.2  Type definition files and IDEs

7.1.3  Shims and type definitions

7.1.4  Creating your own type definition files

7.2  A sample TypeScript app that uses JavaScript libraries

7.3  Introducing TypeScript in your JavaScript project

7.4  Summary