Book Image

TypeScript Essentials

By : Christopher Nance
Book Image

TypeScript Essentials

By: Christopher Nance

Overview of this book

Table of Contents (15 chapters)

Declaration files


Declaration files are a special type of source file in TypeScript and have a different file extension. Declaration files have a file extension of .d.ts and they can contain type information but no implementation details. This includes interface definitions as well as type declarations.

Type declarations are created using the declare keyword, as shown in the following screenshot:

As you can see, the name of the file is Book.d.ts, which is how the compiler knows that this file will only contain declarations. When this occurs, no output file is created and an error will be generated when the implementation code is found in the file. The purpose of these files is to provide type information for other JavaScript libraries that are not in TypeScript files. This allows us to interact with these libraries in a strongly typed fashion, providing compile time checks and intelligent code completion. In the previous example, we declare that the Book class will exist in the global namespace...