Are there lots of examples?
There are loads of examples. The best way to learn is by example, and I have packed as many of them into this book as I can. To maximize the number of examples in this book, I have adopted a simple convention to avoid listing the same code or content repeatedly. When I create a file, I will show its full contents, just as I have in Listing 1.1. I include the name of the file and its folder in the listing’s header, and I show the changes that I have made in bold.
Listing 1.1. Asserting an Unknown Value in the index.ts File in the primer Folderfunction getUKCapital() : string {
return "London";
}
function writeCity(f: () => string) {
console.log(`City: ${f()}`)
}
writeCity(getUKCapital);
writeCity(() => "Paris");
let myCity = "Rome";
writeCity(() => myCity);
This is a listing from Chapter 3, which shows the contents of a file called index.ts
that can be found in the primer
folder. Don’t worry about...