As a TS newcomer, I have a question that surprisingly lacks a clear explanation. What is the main difference between specifying the type to TypeScript in these two ways:
const ul = document.querySelector('#nav') as HTMLUListElement;
and this way:
const ul: HTMLUListElement = document.querySelector('#nav');
I've noticed that TypeScript seems to recognize the type and provide IntelliSense in both scenarios. So why should I use type casting here as recommended by other developers?
Thank you in advance.