{"id":15173,"date":"2021-06-09T12:20:31","date_gmt":"2021-06-09T10:20:31","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=15173"},"modified":"2022-01-05T20:02:43","modified_gmt":"2022-01-05T19:02:43","slug":"understanding-the-role-of-decorators-in-typescript","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/","title":{"rendered":"Understanding the Role of Decorators in TypeScript"},"content":{"rendered":"\n<p><strong>Decorators in <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/web-developer\/learning-typescript\/\" class=\"ek-link\">TypeScript <\/a><\/strong>provide a way of programmatically tapping into the process of defining a class. <\/p>\n\n\n\n<p>Remember that a class definition describes the <strong>shape <\/strong>of a class, what properties it has, and what methods it defines. When an instance of a class is created, these properties and methods become available on the class instance. <\/p>\n\n\n\n<p>Decorators, however, allow us to inject code into the actual definition of a class, before a class instance has been created. They are&nbsp;similar to&nbsp;attributes in C#, or annotations in Java.&nbsp;<\/p>\n\n\n\n<p><em>This article is an excerpt from the book,\u00a0<\/em><a href=\"https:\/\/www.amazon.com\/Mastering-TypeScript-enterprise-ready-applications-frameworks\/dp\/1800564732?maas=maas_adg_FC42A309FBD655918AE3730D1CEE3666_afap_abs&amp;ref_=aa_maas\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>Mastering Typescript, Fourth Edition<\/em><\/strong><\/a><strong><em>\u00a0by Nathan Rozentals\u00a0<\/em><\/strong><em>\u2013 a comprehensive guide for readers to build enterprise-ready, modular\u00a0web applications using Typescript 4 and modern frameworks.\u00a0<\/em>\u00a0<\/p>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-3f57278f      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#decorator-overview\" class=\"uagb-toc-link__trigger\">Decorator overview\u00a0<\/a><li class=\"uagb-toc__list\"><a href=\"#decorator-setup\" class=\"uagb-toc-link__trigger\">Decorator setup\u00a0<\/a><li class=\"uagb-toc__list\"><a href=\"#decorator-syntax\" class=\"uagb-toc-link__trigger\">Decorator syntax\u00a0<\/a><li class=\"uagb-toc__list\"><a href=\"#multiple-decorators\" class=\"uagb-toc-link__trigger\">Multiple decorators\u00a0<\/a><li class=\"uagb-toc__list\"><a href=\"#types-of-decorators\" class=\"uagb-toc-link__trigger\">Types of decorators\u00a0<\/a><li class=\"uagb-toc__list\"><a href=\"#decorator-factories\" class=\"uagb-toc-link__trigger\">Decorator factories\u00a0<\/a><li class=\"uagb-toc__list\"><a href=\"#summary\" class=\"uagb-toc-link__trigger\">Summary\u00a0<\/a><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<h2 class=\"wp-block-heading\" id=\"h-decorator-overview\">Decorator overview&nbsp;<\/h2>\n\n\n\n<p>In this&nbsp;section, we will&nbsp;take a look&nbsp;at the general setup and syntax of decorators, what you need to do to enable them, and how they are applied to classes. We will also show how <strong>multiple decorators <\/strong>can be used at the same time, and then discuss the different types of decorators. <\/p>\n\n\n\n<p>Finally,&nbsp;we\u2019ll&nbsp;take a look&nbsp;at <strong>decorator factories<\/strong>, and how we can pass parameters into decorator functions.&nbsp;<\/p>\n\n\n\n<p>But before diving into our article, don&#8217;t miss the video <strong>The perfect cocktail: Java + Typescript<\/strong>, where open-sourcer Manuel Carrasco Mo\u00f1ino &#8211; with a long history contributions in projects such as Vaadin, Polymer, GWT or Apache &#8211; demonstrates how to develop a 100% type-safe enterprise app, including the back-end, the front-end, and even the data in the wire.<\/p>\n\n\n\n<p>[jwp-video n=&#8221;1&#8243;]<\/p>\n\n\n\n<h2 class=\"gb-headline gb-headline-ff7ab640 gb-headline-text\">Decorator setup&nbsp;<\/h2>\n\n\n\n<p>Decorators are an experimental feature of the TypeScript compiler and are supported in <em>ES5 <\/em>and above. In order to use decorators, you need to enable a compile option in the&nbsp;tsconfig.json&nbsp;file. This option is named&nbsp;experimentalDecorators, and needs to be set to&nbsp;<em>true<\/em>, as follows:&nbsp;<\/p>\n\n\n\n<p>{&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; &#8220;compilerOptions&#8221;: {&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;target&#8221;: &#8220;es5&#8221;,&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;module&#8221;: &#8220;commonjs&#8221;,&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;strict&#8221;: true,&nbsp;<\/p>\n\n\n\n<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;experimentalDecorators&#8221;: true,<\/strong>&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;skipLibCheck&#8221;: true,&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;forceConsistentCasingInFileNames&#8221;: true&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; }&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here, we have set the compiler option named&nbsp;experimentalDecorators&nbsp;to&nbsp;true. This will allow the use of decorators within our TypeScript code.&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-decorator-syntax\">Decorator syntax&nbsp;<\/h2>\n\n\n\n<p>A decorator is a function that is called with a specific set of parameters. These parameters are automatically populated by the <strong>JavaScript runtime<\/strong>, and contain information about the class, method, or property to which the decorator has been applied. <\/p>\n\n\n\n<p>The number of parameters, and their types, determine where a decorator can be applied. To illustrate this syntax, let\u2019s define a <em>class decorator<\/em>, as follows:&nbsp;<\/p>\n\n\n\n<p>function&nbsp;simpleDecorator(constructor: Function) {&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;console.log(&#8216;simpleDecorator&nbsp;called&#8217;);&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here, we have a function named&nbsp;simpleDecorator, which has a single parameter named&nbsp;constructor&nbsp;of the&nbsp;function&nbsp;type, which logs a message to the console, indicating that it has been invoked.<\/p>\n\n\n\n<p>This function, due to the parameters that it defines, can be used as a class decorator function and can be applied to a <em>class definition<\/em>, as follows:&nbsp;<\/p>\n\n\n\n<p>@simpleDecorator&nbsp;<\/p>\n\n\n\n<p>class&nbsp;ClassWithSimpleDecorator&nbsp;{&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here, we have a class named&nbsp;ClassWithSimpleDecorator&nbsp;that has the&nbsp;simpleDecorator&nbsp;decorator applied to it. We apply a decorator using the&nbsp;\u201cat\u201d&nbsp;symbol (@), followed by the name of the decorator function. Running this code will produce the following <em>output<\/em>:&nbsp;<\/p>\n\n\n\n<p>simpleDecorator&nbsp;called&nbsp;<\/p>\n\n\n\n<p>Here, we can see that the&nbsp;simpleDecorator&nbsp;function has been invoked. What is interesting about this code sample, however, is that we have not created an instance of the class named&nbsp;ClassWithSimpleDecorator&nbsp;as yet. <\/p>\n\n\n\n<p>All that we have done is specify the class definition, added a decorator to it, and the decorator has been called by the JavaScript runtime automatically.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Not having to wait for the creation of an instance of a class tells us that decorators are applied when a class is defined. Let\u2019s prove this theory by <em>creating a few instances of this class<\/em>, as follows:&nbsp;<\/p>\n\n\n\n<p>let instance_1 = new&nbsp;ClassWithSimpleDecorator();&nbsp;<\/p>\n\n\n\n<p>let instance_2 = new&nbsp;ClassWithSimpleDecorator();&nbsp;<\/p>\n\n\n\n<p>console.log(`instance_1 :&nbsp;${JSON.stringify(instance_1)}`);&nbsp;<\/p>\n\n\n\n<p>console.log(`instance_2 :&nbsp;${JSON.stringify(instance_2)}`);&nbsp;<\/p>\n\n\n\n<p>Here, we have created two new instances of&nbsp;ClassWithSimpleDecorator, named&nbsp;instance_1&nbsp;and&nbsp;instance_2. We then log a message to the console to output the value of each class instance. The <em>output <\/em>of this code is as follows:&nbsp;<\/p>\n\n\n\n<p>simpleDecorator&nbsp;called&nbsp;<\/p>\n\n\n\n<p>instance_1 :&nbsp;{}&nbsp;<\/p>\n\n\n\n<p>instance_2 :&nbsp;{}&nbsp;<\/p>\n\n\n\n<p>Here, we can see that the&nbsp;simpleDecorator&nbsp;function has only been called once, even though we have created two instances of the&nbsp;ClassWithSimpleDecorator&nbsp;class.&nbsp;<\/p>\n\n\n\n<p>Decorators are only invoked once, when a class is defined.&nbsp;<\/p>\n\n\n\n<h2 class=\"gb-headline gb-headline-cd59e9d4 gb-headline-text\">Multiple decorators&nbsp;<\/h2>\n\n\n\n<p><strong>Multiple decorators<\/strong> can be applied one after another on the same target. As an example of this, let\u2019s define a second decorator function as follows:&nbsp;<\/p>\n\n\n\n<p>function&nbsp;secondDecorator(constructor: Function) {&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;console.log(`secondDecorator&nbsp;called`);&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here, we have a decorator function named&nbsp;secondDecorator, which also logs a message to the console once it has been invoked. We can now apply both&nbsp;simpleDecorator&nbsp;(from our earlier code snippet) and&nbsp;secondDecorator&nbsp;as follows:&nbsp;<\/p>\n\n\n\n<p>@simpleDecorator&nbsp;<\/p>\n\n\n\n<p>@secondDecorator&nbsp;<\/p>\n\n\n\n<p>class&nbsp;ClassWithMultipleDecorators&nbsp;{&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here, we have applied both decorators to a class named&nbsp;ClassWithMultipleDecorators. The output of this code is as follows:&nbsp;<\/p>\n\n\n\n<p>secondDecorator&nbsp;called&nbsp;<\/p>\n\n\n\n<p>simpleDecorator&nbsp;called&nbsp;<\/p>\n\n\n\n<p>Here, we can see that&nbsp;both of the decorators&nbsp;have logged a message to the console. What is interesting, however, is the order in which they are called.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Decorators are called in the reverse order of their appearance within our code.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-types-of-decorators\">Types of decorators&nbsp;<\/h2>\n\n\n\n<p>Decorators, as mentioned earlier, are functions that are invoked by the JavaScript runtime when a class is defined. Depending on what type of decorator is used, these decorator functions will be invoked with different arguments. Let\u2019s take a quick look at the types of decorators, which are:&nbsp;<\/p>\n\n\n\n<ul class=\"is-style-default wp-block-list\"><li>Class decorators \u2013 These are decorators that can be applied to a class definition.&nbsp;<\/li><li>Property decorators \u2013 These are decorators that can be applied to a property within a class.&nbsp;&nbsp;<\/li><li>Method decorators \u2013 These are decorators that can be applied to a method on a class.&nbsp;<\/li><li>Parameter decorators \u2013 These are decorators that can be applied to a parameter of a method within a class.&nbsp;<\/li><\/ul>\n\n\n\n<p>As an example of these types of decorators, consider the following code:&nbsp;<\/p>\n\n\n\n<p>function&nbsp;classDecorator(&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; constructor: Function) {}&nbsp;<\/p>\n\n\n\n<p>function&nbsp;propertyDecorator(&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; target: any,&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;propertyKey: string) {}&nbsp;<\/p>\n\n\n\n<p>function&nbsp;methodDecorator(&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; target: any,&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;methodName: string,&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;descriptor?:&nbsp;PropertyDescriptor) {}&nbsp;<\/p>\n\n\n\n<p>function&nbsp;parameterDecorator(&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; target: any,&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;methodName: string,&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;parameterIndex: number) {}&nbsp;<\/p>\n\n\n\n<p>Here, we have four functions, each with slightly different parameters.&nbsp;&nbsp;<\/p>\n\n\n\n<ul class=\"is-style-default wp-block-list\"><li><strong>The first function<\/strong>, named&nbsp;classDecorator, has a single parameter named&nbsp;constructor&nbsp;of the&nbsp;function&nbsp;type. This function can be used as a class decorator.&nbsp;<\/li><li><strong>The second function<\/strong>, named&nbsp;propertyDecorator, has two parameters. The first parameter is named&nbsp;target, and&nbsp;is of the&nbsp;any&nbsp;type. The second parameter is named&nbsp;propertyKey&nbsp;and is of the&nbsp;string&nbsp;type. This function can be used as a property decorator.&nbsp;<\/li><li><strong>The third function<\/strong>, named&nbsp;methodDecorator, has three parameters. The first parameter, named&nbsp;target, is of the&nbsp;any&nbsp;type, and the second parameter is named&nbsp;methodName, and is of the&nbsp;string&nbsp;type. The third parameter is an optional parameter named&nbsp;descriptor, and&nbsp;is of the&nbsp;PropertyDescriptor&nbsp;type. This function can be used as a method decorator.&nbsp;<\/li><li><strong>The fourth function<\/strong> is named&nbsp;parameterDecorator,&nbsp;and also&nbsp;has three parameters. The first parameter is named&nbsp;target, and&nbsp;is of the&nbsp;any&nbsp;type. The second parameter is named&nbsp;methodName, and is of the&nbsp;string&nbsp;type. The third parameter is named&nbsp;parameterIndex, and is of the&nbsp;number&nbsp;type. This function can be used as a parameter decorator.&nbsp;<\/li><\/ul>\n\n\n\n<p>Let\u2019s now&nbsp;take a look&nbsp;at how we would <em>use<\/em> each of these decorators as follows:&nbsp;<\/p>\n\n\n\n<p>@classDecorator&nbsp;<\/p>\n\n\n\n<p>class&nbsp;ClassWithAllTypesOfDecorators&nbsp;{&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; @propertyDecorator&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; id: number =&nbsp;1;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; @methodDecorator&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;print()&nbsp;{ }&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;setId(@parameterDecorator id: number)&nbsp;{ }&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here, we have a class named&nbsp;ClassWithAllTypesOfDecorators. This class has an&nbsp;id&nbsp;property of the&nbsp;number&nbsp;type, a&nbsp;print&nbsp;method, and a&nbsp;setId&nbsp;method. The class itself has been decorated by our&nbsp;classDecorator, and the&nbsp;id&nbsp;property has been decorated by the&nbsp;propertyDecorator. <\/p>\n\n\n\n<p>The&nbsp;print&nbsp;method has been decorated by the&nbsp;methodDecorator&nbsp;function, and the&nbsp;id&nbsp;parameter of the&nbsp;setId&nbsp;function has been decorated by the&nbsp;parameterDecorator.&nbsp;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>What is important to note about decorators is that it is the number of parameters and their types that distinguish whether they can be used as class, property, method, or parameter decorators. Again, the JavaScript runtime will fill in each of these parameters at runtime.&nbsp;<\/p><\/blockquote>\n\n\n\n<h2 class=\"gb-headline gb-headline-c145a60d gb-headline-text\">Decorator factories&nbsp;<\/h2>\n\n\n\n<p>On occasion, you will need to define a decorator that has parameters. In order to achieve this, we will need to use what is known as a <strong>decorator factory function<\/strong>. A decorator factory function is created by wrapping the decorator function itself within a function, as follows:&nbsp;<\/p>\n\n\n\n<p>function&nbsp;decoratorFactory(name: string) {&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; return (constructor: Function) =&gt; {&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(`decorator function called&nbsp;with :&nbsp;${name}`);&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; }&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here, we have a function named&nbsp;decoratorFactory&nbsp;that accepts a single parameter named&nbsp;name&nbsp;of the&nbsp;string&nbsp;type. Within this function, we return an <em>anonymous function<\/em> that has a single parameter named&nbsp;constructor&nbsp;of the&nbsp;function&nbsp;type. <\/p>\n\n\n\n<p>This anonymous function is our decorator function&nbsp;itself, and&nbsp;will be called by the JavaScript runtime with a single argument. <\/p>\n\n\n\n<p>Within the decorator function, we are logging a message to the console that includes the name parameter passed in to the&nbsp;decoratorFactory&nbsp;function. You can now use this decorator factory as follows:&nbsp;<\/p>\n\n\n\n<p>@decoratorFactory(&#8216;testName&#8217;)&nbsp;<\/p>\n\n\n\n<p>class&nbsp;ClassWithDecoratorFactory&nbsp;{&nbsp;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<p>Here we have applied the decorator named&nbsp;decoratorFactory&nbsp;to a class named&nbsp;ClassWithDecoratorFactory, and supplied the string value of&nbsp;\u201ctestName\u201d&nbsp;as the name argument. The <em>output <\/em>of this code is as follows:&nbsp;<\/p>\n\n\n\n<p>decorator function called&nbsp;with :&nbsp;testName&nbsp;<\/p>\n\n\n\n<p>Here, we can see that the anonymous function returned by the&nbsp;decoratorFactory&nbsp;function was invoked with the string&nbsp;\u201ctestName\u201d&nbsp;as the value of the&nbsp;name&nbsp;argument.&nbsp;<\/p>\n\n\n\n<p>There are two things to note regarding decorator factory functions. <\/p>\n\n\n\n<ol class=\"is-style-default wp-block-list\"><li>Firstly, they must return a function that has the correct number of parameters, and types of parameters, depending on what type of decorator they are. <\/li><li>Secondly, the parameters defined for the decorator factory function can be used anywhere within the function definition, which includes within the anonymous decorator function itself.&nbsp;<\/li><\/ol>\n\n\n\n<p>This concludes our discussion of the setup and use of decorators.&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-summary\">Summary&nbsp;<\/h2>\n\n\n\n<p>In this article, we have explored the use of decorators within TypeScript. We started by setting up our environment to make use of decorators, and then discussed the syntax used to apply decorators. <\/p>\n\n\n\n<p>You can&nbsp;apply decorators to classes, class properties, class methods, and even class parameters.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Decorators in TypeScript provide a way of programmatically tapping into the process of defining a class. Remember that a class definition describes the shape of a class, what properties it has, and what methods it defines. When an instance of a class is created, these properties and methods become available on the class instance. Decorators,&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\">Read more<\/a><\/p>\n","protected":false},"author":124,"featured_media":15214,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":6,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[36],"tags":[9907],"collections":[],"class_list":{"0":"post-15173","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-backend","8":"tag-frameworks","9":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Understanding the Role of Decorators in TypeScript -<\/title>\n<meta name=\"description\" content=\"See how to programmatically inject code into the definition of a class, before a class instance has been created - with syntax examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Understanding the Role of Decorators in TypeScript\" \/>\n<meta property=\"og:description\" content=\"See how to programmatically inject code into the definition of a class, before a class instance has been created - with syntax examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-09T10:20:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-05T19:02:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nathan Rozentals\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nathan Rozentals\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\"},\"author\":{\"name\":\"Nathan Rozentals\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/adae432ed50182e0f36e665bd193e1f7\"},\"headline\":\"Understanding the Role of Decorators in TypeScript\",\"datePublished\":\"2021-06-09T10:20:31+00:00\",\"dateModified\":\"2022-01-05T19:02:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\"},\"wordCount\":2088,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg\",\"keywords\":[\"Frameworks\"],\"articleSection\":[\"Backend\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\",\"name\":\"Understanding the Role of Decorators in TypeScript -\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg\",\"datePublished\":\"2021-06-09T10:20:31+00:00\",\"dateModified\":\"2022-01-05T19:02:43+00:00\",\"description\":\"See how to programmatically inject code into the definition of a class, before a class instance has been created - with syntax examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg\",\"width\":1200,\"height\":628,\"caption\":\"Understanding the Role of Decorators in TypeScript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Backend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/backend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Understanding the Role of Decorators in TypeScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/adae432ed50182e0f36e665bd193e1f7\",\"name\":\"Nathan Rozentals\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/045abb76b2f9ca55c6142b9143954bf7e1aae2d05cf7f20ecc10115a99b3f98f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/045abb76b2f9ca55c6142b9143954bf7e1aae2d05cf7f20ecc10115a99b3f98f?s=96&d=mm&r=g\",\"caption\":\"Nathan Rozentals\"},\"description\":\"Nathan Rozentals has been writing commercial software for over 30 years, in C, C++, Java and C#. He picked up TypeScript within a week after its initial release in October 2012 and realized how much TypeScript could help when writing JavaScript. He was one of the first people to start blogging about TypeScript, discussing early frameworks such as Backbone, Marionette, ExtJS and AngularJs. He knew he'd hit the mark when Microsoft staff started to reference his blog posts in their CodePlex discussion forums. Nathan\u2019s TypeScript solutions now control User Interfaces in IoT devices, run as stand-alone applications for Point-of-Sale solutions, provide complex application configuration web sites, and are used for mission-critical server APIs.\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/nathan-rozentals\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Understanding the Role of Decorators in TypeScript -","description":"See how to programmatically inject code into the definition of a class, before a class instance has been created - with syntax examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/","og_locale":"en_US","og_type":"article","og_title":"Understanding the Role of Decorators in TypeScript","og_description":"See how to programmatically inject code into the definition of a class, before a class instance has been created - with syntax examples.","og_url":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2021-06-09T10:20:31+00:00","article_modified_time":"2022-01-05T19:02:43+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg","type":"image\/jpeg"}],"author":"Nathan Rozentals","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Nathan Rozentals","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/"},"author":{"name":"Nathan Rozentals","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/adae432ed50182e0f36e665bd193e1f7"},"headline":"Understanding the Role of Decorators in TypeScript","datePublished":"2021-06-09T10:20:31+00:00","dateModified":"2022-01-05T19:02:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/"},"wordCount":2088,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg","keywords":["Frameworks"],"articleSection":["Backend"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/","url":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/","name":"Understanding the Role of Decorators in TypeScript -","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg","datePublished":"2021-06-09T10:20:31+00:00","dateModified":"2022-01-05T19:02:43+00:00","description":"See how to programmatically inject code into the definition of a class, before a class instance has been created - with syntax examples.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg","width":1200,"height":628,"caption":"Understanding the Role of Decorators in TypeScript"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/understanding-the-role-of-decorators-in-typescript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Backend","item":"https:\/\/www.codemotion.com\/magazine\/backend\/"},{"@type":"ListItem","position":3,"name":"Understanding the Role of Decorators in TypeScript"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/adae432ed50182e0f36e665bd193e1f7","name":"Nathan Rozentals","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/045abb76b2f9ca55c6142b9143954bf7e1aae2d05cf7f20ecc10115a99b3f98f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/045abb76b2f9ca55c6142b9143954bf7e1aae2d05cf7f20ecc10115a99b3f98f?s=96&d=mm&r=g","caption":"Nathan Rozentals"},"description":"Nathan Rozentals has been writing commercial software for over 30 years, in C, C++, Java and C#. He picked up TypeScript within a week after its initial release in October 2012 and realized how much TypeScript could help when writing JavaScript. He was one of the first people to start blogging about TypeScript, discussing early frameworks such as Backbone, Marionette, ExtJS and AngularJs. He knew he'd hit the mark when Microsoft staff started to reference his blog posts in their CodePlex discussion forums. Nathan\u2019s TypeScript solutions now control User Interfaces in IoT devices, run as stand-alone applications for Point-of-Sale solutions, provide complex application configuration web sites, and are used for mission-critical server APIs.","url":"https:\/\/www.codemotion.com\/magazine\/author\/nathan-rozentals\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-600x600.jpg","author_info":{"display_name":"Nathan Rozentals","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/nathan-rozentals\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg",1200,628,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-300x157.jpg",300,157,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-768x402.jpg",768,402,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-1024x536.jpg",1024,536,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg",1200,628,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg",1200,628,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript.jpg",100,52,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2021\/06\/Understanding-the-Role-of-Decorators-in-TypeScript-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Nathan Rozentals","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/nathan-rozentals\/"},"uagb_comment_info":0,"uagb_excerpt":"Decorators in TypeScript provide a way of programmatically tapping into the process of defining a class. Remember that a class definition describes the shape of a class, what properties it has, and what methods it defines. When an instance of a class is created, these properties and methods become available on the class instance. Decorators,&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/15173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/124"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=15173"}],"version-history":[{"count":5,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/15173\/revisions"}],"predecessor-version":[{"id":15403,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/15173\/revisions\/15403"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/15214"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=15173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=15173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=15173"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=15173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}