TypeScript · Junior · Question 43 of 75
What does TypeScript do with const el = document.getElementById('app')?
- ✓Correct answer: Infers
HTMLElement | nulland requires anullcheck - 2Infers
HTMLDivElementautomatically from the page markup - 3Infers
any, because DOM APIs aren't typed in TypeScript
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']).