Skip to content

Instantly share code, notes, and snippets.

@Kasahs
Created August 12, 2017 14:03
Show Gist options
  • Save Kasahs/0efc054a8fb3bcc351afe7f6beed4d31 to your computer and use it in GitHub Desktop.
Save Kasahs/0efc054a8fb3bcc351afe7f6beed4d31 to your computer and use it in GitHub Desktop.
Things I love about Typescript
/* 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