Declaration file typing
As we have seen, declaration files use the declare
and module
keywords to define objects and namespaces. We have also seen that we can use interfaces in the same way that we do within TypeScript, in order to define custom types for variables. Declaration files allow us to use the same syntax that we would in TypeScript to describe types. These types can be used everywhere types are used in normal TypeScript, including function overloading, type unions, classes, and optional properties. Let's take a quick look at these techniques, with a few simple code samples, to illustrate this feature further. This section will cover:
- Function overloading
- Nested namespaces
- Classes
- Static properties and functions
- Abstract classes
- Generics
- Conditional types and inference
We'll begin by taking a look at function overloading.
Function overloading
Declaration files allow for function overloads, where the...