Skip to content

Instantly share code, notes, and snippets.

@santosh
Created September 12, 2018 07:19
Show Gist options
  • Save santosh/b564a248a73d42d8fe5f0eec26a6c646 to your computer and use it in GitHub Desktop.
Save santosh/b564a248a73d42d8fe5f0eec26a6c646 to your computer and use it in GitHub Desktop.
TypeScript type assertions..
// without initilization, message is of 'any' type
// now you won't get intellisense because editor doesn't
// know what type it is..
let message;
message = "abs";
// one example of type assertion
let endswithC = (<string>message).endsWith('c');
// the alternative way
let alternativeWay = (message as string).endsWith('c');
// you would now get intellesense when you do . after brackets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment