I came across the following code in the Typescript docs:
function createSquare(config: SquareConfig): { color: string; area: number } {
let newSquare = {color: "white", area: 100};
if (config.color) {
newSquare.color = config.color;
}
if (config.width) {
newSquare.area = config.width * config.width;
}
return newSquare;
}
If let variables are only visible within their block scope - why does this not throw an error? newSquare is initialised, but then modified within a new block scope where (as I understand it) it should not be visible?