![]() |
VOOZH | about |
Hybrid types are used by TypeScript to refer to types that combine different things such as objects, functions, arrays etc. In this article, we will learn more about Hybrid Types in TypeScript.
In TypeScript, using interfaces or type aliases we can define hybrid types, these declarations may include property signatures (they declare objectlike properties), call signatures (these declare callable behaviour) and index signatures.
Hybrid types are a combination of different type elements, typically including:
In the given example, the Logger interface introduces a mixture of two types of functions: ones that receive messages as arguments and others that do not, in addition, it exposes a property named level and a method called setLevel.
Output
[info] Starting the application.
[debug] Debugging the application.
Let us consider an illustration in which the StringArray interface is a sort of array as well as object meaning it allows using numbers for indexing and has additional properties like length and description.
Output
hello
This array contains strings.