{"id":381,"date":"2022-10-22T14:29:14","date_gmt":"2022-10-22T06:29:14","guid":{"rendered":"https:\/\/islandtropicaman.com\/wp\/?p=381"},"modified":"2022-10-22T14:29:59","modified_gmt":"2022-10-22T06:29:59","slug":"create-enum-in-typescript","status":"publish","type":"post","link":"https:\/\/islandtropicaman.com\/wp\/2022\/10\/22\/create-enum-in-typescript\/","title":{"rendered":"Create Enum in TypeScript"},"content":{"rendered":"<p>Enum is used to define a human-readable name for a specify number or string. The method to use an enum is to put its value into the switch statement. The below program will determine whether a light is on or off using Enum.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nenum LightSwitch {\r\n    On,\r\n    Off\r\n}\r\n<\/pre>\n<p>The above enum has two values, the on and off state for a light switch.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction lightOnOff(state : LightSwitch) {\r\n    switch(state) {\r\n        case LightSwitch.On:\r\n            console.log(&quot;Light's On!&quot;)\r\n            break\r\n        case LightSwitch.Off:\r\n            console.log(&quot;Light's Off!&quot;)\r\n            break\r\n    }\r\n}\r\n\r\nlightOnOff(LightSwitch.On) \/* Light's On! *\/\r\nlightOnOff(LightSwitch.Off) \/* Light's Off! *\/\r\n<\/pre>\n<p>As the user entered the type LightSwitch enum value (on or off) into the above function, the switch statement will print the state of the light switch accordingly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enum is used to define a human-readable name for a specify number or string. The method to use an enum is to put its value into the switch statement. The below program will determine whether a light is on or off using Enum. enum LightSwitch { On, Off } The above enum has two values,&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/islandtropicaman.com\/wp\/2022\/10\/22\/create-enum-in-typescript\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Create Enum in TypeScript&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[114],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-type-script","tag-enum"],"blog_post_layout_featured_media_urls":{"thumbnail":"","full":""},"categories_names":{"38":{"name":"Type-Script","link":"https:\/\/islandtropicaman.com\/wp\/category\/type-script\/"}},"tags_names":{"114":{"name":"enum","link":"https:\/\/islandtropicaman.com\/wp\/tag\/enum\/"}},"comments_number":"0","_links":{"self":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":1,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/381\/revisions\/382"}],"wp:attachment":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}