Created
September 12, 2018 07:19
-
-
Save santosh/b564a248a73d42d8fe5f0eec26a6c646 to your computer and use it in GitHub Desktop.
TypeScript type assertions..
This file contains hidden or 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
// 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