Created
August 12, 2017 14:03
-
-
Save Kasahs/0efc054a8fb3bcc351afe7f6beed4d31 to your computer and use it in GitHub Desktop.
Things I love about Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* strict typing extends to browser API which enables error free code at compile time.*/ | |
// this won't work because querySelector returns type Element | |
let roomNameEl:HTMLElement = el.querySelector('.room-name') | |
// this solves the problem | |
let roomNameEl:Element = el.querySelector('.room-name') | |
// this will not work cause Element doesn't have value attr | |
let roomNameEl:Element = el.querySelector('.room-name') | |
roomNameEl.value // error no such attr | |
// this will work, also notice typecasting is possible | |
let roomNameEl:HTMLInputElement = <HTMLInputElement>el.querySelector('.room-name') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment