June 2025
Intermediate to advanced
837 pages
24h 50m
English
As you’ve already seen in the code examples, TypeScript uses a colon to separate a variable and a return value, respectively, from their respective types. In Listing 13.14 you’ll define a variable of the string type and assign a value to it.
let name: string = 'Sebastian';
Listing 13.14 Declaration of a Variable in TypeScript (index.ts)
In this example, specifying the type can also be omitted because TypeScript does type inference and tries to guess the types. With a direct value assignment, this works reliably. The name variable has the string type across its entire range of validity. If you assign a number or any other data type different from string to it at a later time, this will result in a compiler error. ...
Read now
Unlock full access