February 2019
Beginner
694 pages
18h 4m
English
There are occasions, however, where we would like to declare a variable using the let keyword and use it, before TypeScript thinks that it has been defined. Consider the following code:
let globalString: string;
setGlobalString();
console.log(`globalString : ${globalString}`);
function setGlobalString() {
globalString = "this has been set";
}
Here, we have declared a variable named globalString. We then call a function named setGlobalString, which sets the value of the globalString variable. So, according to the logic of this code, the globalString variable is not undefined, and should contain a value at this stage. The next line of code logs the value of globalString to the console.
Unfortunately, the TypeScript compiler ...
Read now
Unlock full access