TypeScript · Junior · Question 43 of 75

What does TypeScript do with const el = document.getElementById('app')?

Explanation

The element may not exist, so the type includes null. For a specific type, use querySelector<HTMLInputElement>('#email') or an instanceof HTMLInputElement check. DOM types are part of the standard library (lib: ['dom']).

Further reading

Problem with a question

TypeScript · Junior · question 43

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz