Whenever I use the !. operator with typescript, my compilation errors dissapear, but I searched a bit, and I am not clear what !. stands for.
For example, finding a div:
let twelveDiv = Array.from(timePickerDivs).find(element => element.innerHTML === '12')
This produces a compilation error that makes sense:
twelveDiv?.innerHTML = '00'; //The left-hand side of an assignment expression may not be an optional property access.ts(2779)
However the !. solves it:
twelveDiv!.innerHTML = '00'; // no compilation error.
Same for a simple class:
class MyAwesomeClass {
private myNumber: number; //Property 'myNumber' has no initializer and is not definitely assigned in the constructor.ts(2564)
}
In this case both ?. and !. solves the compilation error.
I am familiar with the ?. for the optional properties and arguments in functions/classes, but not that much with the !.. Thanks.