-
Notifications
You must be signed in to change notification settings - Fork 0
Type Assertions
Jorge Castro edited this page Nov 10, 2025
·
1 revision
This won't work because Propery 'value' does not exist on type 'HTMLElement'.
const input1 = document.getElementById('my-input-text');
console.log(input1.value);Even adding a type annotation won't work
const input1: HTMLInputElement = document.getElementById('my-input-text');
console.log(input1.value);Nonetheless, applying a type assertion will work
const input1 = document.getElementById('my-input-text') as HTMLInputElement;
console.log(input1.value);- Sync-Obsidian-with-GitHub-on-iOS
- Obsidian-community-plugins
- Optimizing-Novel-Word-Count-Plugin-for-Git-Users
- What is TypeScript, and why you should use it
- Quick setup
- Inference and type annotations
- Fundamental Types
- Object Types
- Union Types
- Type Aliases and Interfaces
- Type Assertions
- Literal Types
- null and undefined
- Narrowing
- Creating Types from Types
- Common Built‐in and Utility Types
- tsc CLI ‐ (The Compiler)
- Avoid using Object or {}
- Ignoring TypeScript errors
- TypeScript resources